diff options
Diffstat (limited to 'src/errors.rs')
-rw-r--r-- | src/errors.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/errors.rs b/src/errors.rs index 42477c0..c1d6672 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -12,6 +12,9 @@ pub enum ServiceError { #[error("SQL error: {0}")] Sql(#[from] sqlx::Error), + + #[error("Not Found")] + NotFound, } pub type StringResult<T = &'static str> = Result<T, ServiceError>; @@ -22,8 +25,13 @@ impl IntoResponse for ServiceError { fn into_response(self) -> Response { let body = body::boxed(body::Full::from(self.to_string())); + let status = match self { + ServiceError::NotFound => StatusCode::NOT_FOUND, + _ => StatusCode::INTERNAL_SERVER_ERROR, + }; + Response::builder() - .status(StatusCode::INTERNAL_SERVER_ERROR) + .status(status) .body(body) .unwrap() } |