48 lines
1.3 KiB
Rust
48 lines
1.3 KiB
Rust
|
use std::fmt::{Display, Formatter};
|
||
|
|
||
|
use reqwest::Error;
|
||
|
use serenity::Error as SerenityError;
|
||
|
|
||
|
use geoffrey_models::models::response::api_error::GeoffreyAPIError;
|
||
|
|
||
|
#[derive(Debug)]
|
||
|
pub enum BotError {
|
||
|
ArgumentParse(String),
|
||
|
GeoffreyApi(GeoffreyAPIError),
|
||
|
Serenity(serenity::Error),
|
||
|
Reqwest(reqwest::Error),
|
||
|
CommandNotFound(String),
|
||
|
}
|
||
|
|
||
|
impl Display for BotError {
|
||
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||
|
let s = match self {
|
||
|
BotError::ArgumentParse(s) => format!("Unable to parse argument '{}'", s),
|
||
|
BotError::GeoffreyApi(err) => format!("Got error from GeoffreyAPI: {}", err),
|
||
|
BotError::Serenity(err) => format!("Serenity Error: {}", err),
|
||
|
BotError::Reqwest(err) => format!("Reqwest Error: {}", err),
|
||
|
BotError::CommandNotFound(err) => format!("'{}' not found!", err),
|
||
|
};
|
||
|
|
||
|
write!(f, "{}", s)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl From<GeoffreyAPIError> for BotError {
|
||
|
fn from(err: GeoffreyAPIError) -> Self {
|
||
|
Self::GeoffreyApi(err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl From<SerenityError> for BotError {
|
||
|
fn from(err: SerenityError) -> Self {
|
||
|
Self::Serenity(err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl From<reqwest::Error> for BotError {
|
||
|
fn from(err: Error) -> Self {
|
||
|
Self::Reqwest(err)
|
||
|
}
|
||
|
}
|