From 24de79e8f68c6faee0fffc5459d2df5b1d99e9e2 Mon Sep 17 00:00:00 2001 From: Lennart <18233294+lennart-k@users.noreply.github.com> Date: Sun, 10 Nov 2024 13:39:13 +0100 Subject: [PATCH] store: Implement actix ResponseError --- crates/store/src/error.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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, + } + } +}