From 276255f5a20fa05a005e765287239ca5ffe439e4 Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Thu, 9 Jun 2022 10:28:42 -0400 Subject: planets: State manipulation --- src/errors.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/errors.rs') diff --git a/src/errors.rs b/src/errors.rs index d76db92..b22932f 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -12,6 +12,9 @@ pub enum ServiceError { #[error("Axum error: {0}")] Axum(#[from] axum::Error), + + #[error("Not Found")] + NotFound, } pub type StringResult = std::result::Result; @@ -23,8 +26,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() } -- cgit v1.2.3