framework_cqrs_lib/cqrs/models/
errors.rs1use serde::{Deserialize, Serialize};
2use utoipa::ToSchema;
3
4pub type ResultErr<DATA> = Result<DATA, Error>;
5
6#[derive(Serialize, Deserialize, Clone, ToSchema, Debug)]
7pub enum Error {
8 Http(ErrorHttpCustom),
9 Simple(String),
10}
11
12
13#[derive(Serialize, Deserialize, Clone, ToSchema, Debug)]
14pub struct StandardHttpError {
15 pub not_found: ErrorHttpCustom,
16 pub internal_server_error: ErrorHttpCustom,
17 pub unauthorized: ErrorHttpCustom,
18}
19
20impl StandardHttpError {
21 pub fn new() -> Self {
22 Self {
23 not_found: ErrorHttpCustom::new("ressource not found", "00NOTFO", vec![], Some(404)),
24 internal_server_error: ErrorHttpCustom::new("wip", "00INTER", vec![], Some(500)),
25 unauthorized: ErrorHttpCustom::new("wip", "00UNAUT", vec![], Some(401)),
26 }
27 }
28}
29
30#[derive(Serialize, Deserialize, Clone, ToSchema, Debug)]
31pub struct ErrorHttpCustom {
32 #[schema(example = "titre")]
33 pub title: String,
34 #[schema(example = "00EXAMPLE")]
35 pub code: String,
36 #[schema(example = "[]")]
37 pub causes: Vec<Problem>,
38 #[schema(example = "200")]
39 pub status: Option<u16>,
40}
41
42impl ErrorHttpCustom {
43 pub fn new(title: &str, code: &str, problems: Vec<Problem>, status: Option<u16>) -> Self {
44 Self {
45 title: title.to_string(),
46 code: code.to_string(),
47 causes: problems,
48 status,
49 }
50 }
51}
52
53#[derive(Serialize, Deserialize, Clone, ToSchema, Debug)]
54pub struct Problem {
55 #[schema(example = "titre")]
56 pub title: String,
57 #[schema(example = "description")]
58 pub description: String,
59}