use core::{fmt, result};
use std::error;
#[derive(Debug)]
pub enum Error {
InternalClientError(reqwest::Error),
InternalServerError,
NotFound,
Ratelimit {
retry_after: u16,
},
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InternalClientError(err) => write!(f, "internal client error: {err}"),
Self::InternalServerError => write!(f, "internal server error"),
Self::NotFound => write!(f, "not found"),
Self::Ratelimit { retry_after } => write!(
f,
"this client is ratelimited, try again in {} seconds",
retry_after / 60
),
}
}
}
impl error::Error for Error {
#[inline(always)]
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match self {
Self::InternalClientError(err) => err.source(),
_ => None,
}
}
}
pub type Result<T> = result::Result<T, Error>;