mirror of
https://github.com/lennart-k/rustical.git
synced 2026-01-30 12:58:28 +00:00
Initial commit
This commit is contained in:
28
crates/dav/src/error.rs
Normal file
28
crates/dav/src/error.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use actix_web::{http::StatusCode, HttpResponse};
|
||||
use derive_more::{Display, Error};
|
||||
|
||||
#[derive(Debug, Display, Error)]
|
||||
pub enum Error {
|
||||
#[display(fmt = "Internal server error")]
|
||||
InternalError,
|
||||
#[display(fmt = "Not found")]
|
||||
NotFound,
|
||||
#[display(fmt = "Bad request")]
|
||||
BadRequest,
|
||||
Unauthorized,
|
||||
}
|
||||
|
||||
impl actix_web::error::ResponseError for Error {
|
||||
fn status_code(&self) -> StatusCode {
|
||||
match *self {
|
||||
Self::InternalError => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Self::NotFound => StatusCode::NOT_FOUND,
|
||||
Self::BadRequest => StatusCode::BAD_REQUEST,
|
||||
Self::Unauthorized => StatusCode::UNAUTHORIZED,
|
||||
}
|
||||
}
|
||||
|
||||
fn error_response(&self) -> HttpResponse {
|
||||
HttpResponse::build(self.status_code()).body(self.to_string())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user