diff --git a/crates/store/src/error.rs b/crates/store/src/error.rs index 640ccae..ad9a274 100644 --- a/crates/store/src/error.rs +++ b/crates/store/src/error.rs @@ -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, + } + } +}