33 lines
1.2 KiB
Rust
33 lines
1.2 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
use std::fmt::{Display, Formatter};
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
pub enum GeoffreyAPIError {
|
|
PlayerNotRegistered,
|
|
EntryNotFound,
|
|
PermissionInsufficient,
|
|
EntryNotUnique,
|
|
DatabaseError(String),
|
|
TokenNotAuthorized,
|
|
}
|
|
|
|
impl Display for GeoffreyAPIError {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
let string = match self {
|
|
GeoffreyAPIError::PlayerNotRegistered => "Player has not been registered.".to_string(),
|
|
GeoffreyAPIError::EntryNotFound => {
|
|
"An entry that matches that query was not found.".to_string()
|
|
}
|
|
GeoffreyAPIError::PermissionInsufficient => {
|
|
"Insufficient permission to preform that action".to_string()
|
|
}
|
|
GeoffreyAPIError::EntryNotUnique => "Entry not unique in the DB.".to_string(),
|
|
GeoffreyAPIError::DatabaseError(e) => format!("Database Error: {}", e),
|
|
GeoffreyAPIError::TokenNotAuthorized => {
|
|
"Token supplied in request is not authorized".to_string()
|
|
}
|
|
};
|
|
write!(f, "{}", string)
|
|
}
|
|
}
|