1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("IO error: {0}")]
IO(#[from] std::io::Error),
#[error("Config error: {0}")]
Toml(#[from] toml::de::Error),
#[error("Request error: {0}")]
Reqwest(#[from] reqwest::Error),
#[error("Invalid HTTP method")]
Method,
#[error("Serialization error: {0}")]
Serialization(#[from] serde_json::Error),
#[error("Axum error: {0}")]
Axum(#[from] axum::Error),
#[error("Route not found: {0}")]
RouteNotFound(axum::http::Uri),
#[error("Recv Error: {0}")]
Recv(#[from] tokio::sync::watch::error::RecvError),
#[error("Service not found: {0}")]
ServiceNotFound(String),
}
impl axum::response::IntoResponse for Error {
fn into_response(self) -> axum::response::Response {
use axum::http::StatusCode;
let status = match self {
Self::RouteNotFound(_) | Self::ServiceNotFound(_) => StatusCode::NOT_FOUND,
_ => StatusCode::INTERNAL_SERVER_ERROR,
};
(status, self.to_string()).into_response()
}
}
|