diff options
author | Toby Vincent <tobyv@tobyvin.dev> | 2024-09-26 17:31:16 -0500 |
---|---|---|
committer | Toby Vincent <tobyv@tobyvin.dev> | 2024-09-26 17:31:16 -0500 |
commit | fd992d7e3c03f37fbcafe9d3f26c72a2ead3b2a7 (patch) | |
tree | f3e29427d1bbe4a8d6e050abbd9f66afb5fa2152 /src/error.rs | |
parent | cbfca14b38806798847e3f2008038b25194a9b8b (diff) |
feat!: impl full api
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 22 |
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() + } } |