summaryrefslogtreecommitdiffstats
path: root/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs
index ef30b97..109c944 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -13,4 +13,26 @@ pub enum Error {
#[error("Invalid HTTP method")]
Method,
+
+ #[error("Axum error: {0}")]
+ Axum(#[from] axum::Error),
+
+ #[error("Route not found: {0}")]
+ RouteNotFound(axum::http::Uri),
+
+ #[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()
+ }
}