34 lines
929 B
Rust
34 lines
929 B
Rust
// I can probably do this way easier using an external crate, I should do that
|
|
use rocket::http::Status;
|
|
|
|
/// Represents any general error that the API can encounter during execution.
|
|
/// It allows us to more easily process errors, and hopefully allows for
|
|
/// more clear error messages.
|
|
#[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
|
|
}
|
|
}
|