Geoffrey-rs/geoffrey_models/src/models/response/api_error.rs

41 lines
1.5 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),
}
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)
}
};
write!(f, "{}", string)
}
}