mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 22:52:22 +00:00
store: Implement actix ResponseError
This commit is contained in:
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user