2020-04-20 08:44:29 +00:00
|
|
|
extern crate diesel;
|
|
|
|
|
|
|
|
use std::fmt;
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Error {
|
2020-05-10 16:28:11 +00:00
|
|
|
// The player has already reached the max character limit
|
2020-04-20 08:44:29 +00:00
|
|
|
CharacterLimitReached,
|
|
|
|
// An error occured when performing a database action
|
|
|
|
DatabaseError(diesel::result::Error),
|
2020-05-11 10:06:53 +00:00
|
|
|
// Unable to load body or stats for a character
|
|
|
|
CharacterDataError,
|
2020-04-20 08:44:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for Error {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
write!(f, "{}", match self {
|
|
|
|
Self::DatabaseError(diesel_error) => diesel_error.to_string(),
|
|
|
|
Self::CharacterLimitReached => String::from("Character limit exceeded"),
|
2020-05-11 10:06:53 +00:00
|
|
|
Self::CharacterDataError => String::from("Error while loading character data"),
|
2020-04-20 08:44:29 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<diesel::result::Error> for Error {
|
|
|
|
fn from(error: diesel::result::Error) -> Error { Error::DatabaseError(error) }
|
|
|
|
}
|