53 lines
2.0 KiB
Rust
53 lines
2.0 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,
|
|
MultipleLocationsMatch,
|
|
ParameterInvalid(String),
|
|
PlayerRegistrationWithoutMCUUID,
|
|
AccountLinkInvalid,
|
|
InvalidRegex(String),
|
|
}
|
|
|
|
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()
|
|
}
|
|
GeoffreyAPIError::MultipleLocationsMatch => {
|
|
"The location query returned multiple locations.".to_string()
|
|
}
|
|
GeoffreyAPIError::ParameterInvalid(param) => {
|
|
format!("Parameter \"{}\" is invalid", param)
|
|
}
|
|
GeoffreyAPIError::PlayerRegistrationWithoutMCUUID => {
|
|
"Players can only registered with a MC UUID".to_string()
|
|
}
|
|
GeoffreyAPIError::AccountLinkInvalid => {
|
|
"The supplied account link code is invalid".to_string()
|
|
}
|
|
GeoffreyAPIError::InvalidRegex(err) => {
|
|
format!("Invalid regex supplied: {}", err)
|
|
}
|
|
};
|
|
write!(f, "{}", string)
|
|
}
|
|
}
|