1use std::fmt::{Display, Formatter};
2use std::net::AddrParseError;
3
4use reqwest::header::InvalidHeaderValue;
5
6#[derive(Debug)]
8pub enum DehashedError {
9 ReqwestError(reqwest::Error),
11 Unauthorized,
13 InvalidQuery,
15 RateLimited,
17 Unknown(String),
19 ParseIntError(std::num::ParseIntError),
21 ParseAddrError(AddrParseError),
23 InvalidApiKey(InvalidHeaderValue),
25}
26
27impl Display for DehashedError {
28 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
29 match self {
30 DehashedError::ReqwestError(err) => write!(f, "Reqwest error occurred: {err}"),
31 DehashedError::Unauthorized => write!(f, "Invalid API credentials"),
32 DehashedError::InvalidQuery => write!(f, "The provided query is missing or invalid"),
33 DehashedError::RateLimited => write!(f, "The account got rate limited"),
34 DehashedError::Unknown(err) => write!(f, "An unknown error occurred: {err}"),
35 DehashedError::ParseIntError(err) => {
36 write!(f, "An error occurred while parsing a response: {err}")
37 }
38 DehashedError::ParseAddrError(err) => write!(f, "Error while parsing ip addr: {err}"),
39 DehashedError::InvalidApiKey(err) => {
40 write!(f, "Invalid API key, could not put in header: {err}")
41 }
42 }
43 }
44}
45
46impl std::error::Error for DehashedError {}
47
48impl From<reqwest::Error> for DehashedError {
49 fn from(value: reqwest::Error) -> Self {
50 Self::ReqwestError(value)
51 }
52}
53
54impl From<std::num::ParseIntError> for DehashedError {
55 fn from(value: std::num::ParseIntError) -> Self {
56 Self::ParseIntError(value)
57 }
58}
59
60impl From<AddrParseError> for DehashedError {
61 fn from(value: AddrParseError) -> Self {
62 Self::ParseAddrError(value)
63 }
64}
65
66impl From<InvalidHeaderValue> for DehashedError {
67 fn from(value: InvalidHeaderValue) -> Self {
68 Self::InvalidApiKey(value)
69 }
70}