use std::fmt::{Display, Formatter};
use std::net::AddrParseError;
#[derive(Debug)]
pub enum DehashedError {
ReqwestError(reqwest::Error),
Unauthorized,
InvalidQuery,
RateLimited,
Unknown,
ParseIntError(std::num::ParseIntError),
ParseAddrError(AddrParseError),
}
impl Display for DehashedError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
DehashedError::ReqwestError(err) => write!(f, "Reqwest error occurred: {err}"),
DehashedError::Unauthorized => write!(f, "Invalid API credentials"),
DehashedError::InvalidQuery => write!(f, "The provided query is missing or invalid"),
DehashedError::RateLimited => write!(f, "The account got rate limited"),
DehashedError::Unknown => write!(f, "An unknown error occurred"),
DehashedError::ParseIntError(err) => {
write!(f, "An error occurred while parsing a response: {err}")
}
DehashedError::ParseAddrError(err) => write!(f, "Error while parsing ip addr: {err}"),
}
}
}
impl std::error::Error for DehashedError {}
impl From<reqwest::Error> for DehashedError {
fn from(value: reqwest::Error) -> Self {
Self::ReqwestError(value)
}
}
impl From<std::num::ParseIntError> for DehashedError {
fn from(value: std::num::ParseIntError) -> Self {
Self::ParseIntError(value)
}
}
impl From<AddrParseError> for DehashedError {
fn from(value: AddrParseError) -> Self {
Self::ParseAddrError(value)
}
}