From fd992d7e3c03f37fbcafe9d3f26c72a2ead3b2a7 Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Thu, 26 Sep 2024 17:31:16 -0500 Subject: feat!: impl full api --- src/error.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/error.rs') 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() + } } -- cgit v1.2.3-70-g09d2