web_server_abstraction/
error.rs1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, WebServerError>;
7
8#[derive(Error, Debug)]
10pub enum WebServerError {
11 #[error("IO error: {0}")]
12 IoError(#[from] std::io::Error),
13
14 #[error("JSON error: {0}")]
15 JsonError(#[from] serde_json::Error),
16
17 #[error("UTF-8 error: {0}")]
18 Utf8Error(#[from] std::string::FromUtf8Error),
19
20 #[error("HTTP error: {0}")]
21 HttpError(#[from] http::Error),
22
23 #[error("Bind error: {0}")]
24 BindError(String),
25
26 #[error("Route error: {0}")]
27 RouteError(String),
28
29 #[error("Middleware error: {0}")]
30 MiddlewareError(String),
31
32 #[error("Framework adapter error: {0}")]
33 AdapterError(String),
34
35 #[error("Configuration error: {0}")]
36 ConfigError(String),
37
38 #[error("Authentication error: {0}")]
39 AuthError(String),
40
41 #[error("Custom error: {0}")]
42 Custom(String),
43}
44
45impl WebServerError {
46 pub fn custom(msg: impl Into<String>) -> Self {
48 Self::Custom(msg.into())
49 }
50
51 pub fn bind_error(msg: impl Into<String>) -> Self {
53 Self::BindError(msg.into())
54 }
55
56 pub fn route_error(msg: impl Into<String>) -> Self {
58 Self::RouteError(msg.into())
59 }
60
61 pub fn middleware_error(msg: impl Into<String>) -> Self {
63 Self::MiddlewareError(msg.into())
64 }
65
66 pub fn adapter_error(msg: impl Into<String>) -> Self {
68 Self::AdapterError(msg.into())
69 }
70
71 pub fn parse_error(msg: impl Into<String>) -> Self {
73 Self::Custom(format!("Parse error: {}", msg.into()))
74 }
75}