store: Implement actix ResponseError

This commit is contained in:
Lennart
2024-11-10 13:39:13 +01:00
parent 9cc2b37a2e
commit 24de79e8f6

View File

@@ -1,3 +1,5 @@
use actix_web::{http::StatusCode, ResponseError};
#[derive(Debug, thiserror::Error)]
pub enum Error {
@@ -16,3 +18,14 @@ pub enum Error {
#[error(transparent)]
Other(#[from] anyhow::Error),
}
impl ResponseError for Error {
fn status_code(&self) -> actix_web::http::StatusCode {
match self {
Self::NotFound => StatusCode::NOT_FOUND,
Self::AlreadyExists => StatusCode::CONFLICT,
Self::InvalidData(_) => StatusCode::BAD_REQUEST,
_ => StatusCode::INTERNAL_SERVER_ERROR,
}
}
}