1use thiserror::Error;
4
5#[derive(Error, Debug)]
7pub enum Error {
8 #[error("HTTP error: {0}")]
9 Http(String),
10
11 #[error("DI error: {0}")]
12 Di(String),
13
14 #[error("Routing error: {0}")]
15 Routing(String),
16
17 #[error("Serialization error: {0}")]
18 Serialization(#[from] serde_json::Error),
19
20 #[error("Internal error: {0}")]
21 Internal(String),
22
23 #[error("{0}")]
24 Message(String),
25
26 #[error("{0}")]
28 Validation(String),
29
30 #[error("{0}")]
32 NotFound(String),
33
34 #[error("{0}")]
36 Conflict(String),
37}
38
39impl Error {
40 pub fn status_code(&self) -> u16 {
45 match self {
46 Error::Http(_) => 400,
47 Error::Di(_) => 500,
48 Error::Routing(_) => 404,
49 Error::Serialization(_) => 400,
50 Error::Internal(_) => 500,
51 Error::Message(_) => 500,
52 Error::Validation(_) => 400,
53 Error::NotFound(_) => 404,
54 Error::Conflict(_) => 409,
55 }
56 }
57}
58
59pub type Result<T> = std::result::Result<T, Error>;