1use std::{error, fmt, string};
3
4#[derive(Debug)]
6#[non_exhaustive]
7pub enum Error {
8 #[cfg(feature = "async-impl")]
10 Reqwest(reqwest::Error),
11 #[cfg(feature = "blocking")]
13 Ureq(ureq::Error),
14 Decode(base64::DecodeError),
16 FromUtf8(string::FromUtf8Error),
18 Regex(&'static str),
20 LinkCannotBeDecoded(String),
22}
23
24impl error::Error for Error {}
25
26impl fmt::Display for Error {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 match self {
29 #[cfg(feature = "async-impl")]
30 Self::Reqwest(error) => write!(f, "Reqwest: {error}"),
31 #[cfg(feature = "blocking")]
32 Self::Ureq(error) => write!(f, "Ureq: {error}"),
33 Self::Decode(error) => write!(f, "Decode: {error}"),
34 Self::FromUtf8(error) => write!(f, "FromUtf8: {error}"),
35 Self::Regex(msg) => write!(f, "Regex: {msg}"),
36 Self::LinkCannotBeDecoded(v) => write!(f, "Src: {v} cannot be decoded"),
37 }
38 }
39}
40
41#[cfg(feature = "async-impl")]
42impl From<reqwest::Error> for Error {
43 fn from(value: reqwest::Error) -> Self {
44 Self::Reqwest(value)
45 }
46}
47
48#[cfg(feature = "blocking")]
49impl From<ureq::Error> for Error {
50 fn from(value: ureq::Error) -> Self {
51 Self::Ureq(value)
52 }
53}
54
55impl From<base64::DecodeError> for Error {
56 fn from(value: base64::DecodeError) -> Self {
57 Self::Decode(value)
58 }
59}
60
61impl From<string::FromUtf8Error> for Error {
62 fn from(value: string::FromUtf8Error) -> Self {
63 Self::FromUtf8(value)
64 }
65}