fej/src/errors.rs

31 lines
747 B
Rust

// I can probably do this way easier using an external crate, I should do that
use rocket::http::Status;
#[derive(Debug, PartialEq)]
pub enum FejError {
InvalidArgument,
FailedRequest,
}
impl From<FejError> for Status {
fn from(err: FejError) -> Status {
match err {
FejError::InvalidArgument => Status::BadRequest,
FejError::FailedRequest => Status::InternalServerError,
}
}
}
// TODO make this more advanced where possible
impl From<reqwest::Error> for FejError {
fn from(_: reqwest::Error) -> FejError {
FejError::FailedRequest
}
}
impl From<chrono::ParseError> for FejError {
fn from(_: chrono::ParseError) -> FejError {
FejError::InvalidArgument
}
}