use std::{
error::Error,
fmt::{self, Debug, Display},
};
#[derive(Debug)]
pub enum LibVeeziError {
Http(reqwest::Error),
UrlParse(url::ParseError),
}
impl Display for LibVeeziError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Http(err) => write!(f, "HTTP error: {err}"),
Self::UrlParse(err) => write!(f, "URL parse error: {err}"),
}
}
}
impl Error for LibVeeziError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::Http(err) => Some(err),
Self::UrlParse(err) => Some(err),
}
}
}
impl From<reqwest::Error> for LibVeeziError {
fn from(err: reqwest::Error) -> Self {
Self::Http(err)
}
}
impl From<url::ParseError> for LibVeeziError {
fn from(err: url::ParseError) -> Self {
Self::UrlParse(err)
}
}
pub type ApiResult<T> = Result<T, LibVeeziError>;