summaryrefslogtreecommitdiff
path: root/src/errors.rs
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2022-05-30 00:01:39 -0400
committerCara Salter <cara@devcara.com>2022-05-30 00:01:39 -0400
commit3ec1485ae7856e76db8eb2f305ef5950e60f7d8c (patch)
tree09885a51cfc3fe9d2ba45356df2347ec59ee2c22 /src/errors.rs
parent7ba652e291bb52d97faa6d21e7821a64664a00ae (diff)
downloadhomeworld-3ec1485ae7856e76db8eb2f305ef5950e60f7d8c.tar.gz
homeworld-3ec1485ae7856e76db8eb2f305ef5950e60f7d8c.zip
errors/handlers: Make 404 errors more clear
Instead of returning a 500 for every error, this should make it a little easier to return specific status codes for different errors
Diffstat (limited to 'src/errors.rs')
-rw-r--r--src/errors.rs10
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()
}