2021-04-08 10:11:15 +02:00
|
|
|
// I can probably do this way easier using an external crate, I should do that
|
2021-04-04 13:03:08 +02:00
|
|
|
use rocket::http::Status;
|
|
|
|
|
2021-04-12 21:33:56 +02:00
|
|
|
/// 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.
|
2021-04-08 22:39:04 +02:00
|
|
|
#[derive(Debug, PartialEq)]
|
2021-04-04 13:03:08 +02:00
|
|
|
pub enum FejError {
|
|
|
|
InvalidArgument,
|
|
|
|
FailedRequest,
|
2021-04-17 22:39:22 +02:00
|
|
|
DatabaseError,
|
2021-04-04 13:03:08 +02:00
|
|
|
}
|
|
|
|
|
2021-04-16 00:36:03 +02:00
|
|
|
// I'd love to move this over to the server binary, but right now, error E0117 is making that
|
|
|
|
// imopssible
|
2021-04-04 13:03:08 +02:00
|
|
|
impl From<FejError> for Status {
|
|
|
|
fn from(err: FejError) -> Status {
|
|
|
|
match err {
|
|
|
|
FejError::InvalidArgument => Status::BadRequest,
|
|
|
|
FejError::FailedRequest => Status::InternalServerError,
|
2021-04-17 22:39:22 +02:00
|
|
|
FejError::DatabaseError => Status::InternalServerError,
|
2021-04-04 13:03:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO make this more advanced where possible
|
2021-04-05 11:00:41 +02:00
|
|
|
impl From<reqwest::Error> for FejError {
|
|
|
|
fn from(_: reqwest::Error) -> FejError {
|
2021-04-04 13:03:08 +02:00
|
|
|
FejError::FailedRequest
|
|
|
|
}
|
|
|
|
}
|
2021-04-08 10:11:15 +02:00
|
|
|
|
|
|
|
impl From<chrono::ParseError> for FejError {
|
|
|
|
fn from(_: chrono::ParseError) -> FejError {
|
|
|
|
FejError::InvalidArgument
|
|
|
|
}
|
|
|
|
}
|
2021-04-17 22:39:22 +02:00
|
|
|
|
|
|
|
impl From<diesel::result::Error> for FejError {
|
|
|
|
fn from(_: diesel::result::Error) -> FejError {
|
|
|
|
FejError::DatabaseError
|
|
|
|
}
|
|
|
|
}
|