Refactor errors and some other stuff/fixes
This commit is contained in:
parent
8d996888bd
commit
5a7b2de0ea
28 changed files with 507 additions and 341 deletions
emgauwa-lib/src/errors
25
emgauwa-lib/src/errors/api_error.rs
Normal file
25
emgauwa-lib/src/errors/api_error.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
use actix_web::http::StatusCode;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ApiError {
|
||||
ProtectedSchedule,
|
||||
InternalError(String),
|
||||
}
|
||||
|
||||
impl ApiError {
|
||||
pub fn get_code(&self) -> StatusCode {
|
||||
match self {
|
||||
ApiError::ProtectedSchedule => StatusCode::FORBIDDEN,
|
||||
ApiError::InternalError(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&ApiError> for String {
|
||||
fn from(err: &ApiError) -> Self {
|
||||
match err {
|
||||
ApiError::ProtectedSchedule => String::from("the targeted schedule is protected"),
|
||||
ApiError::InternalError(msg) => msg.clone(),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue