1#[derive(Debug)]
3pub enum Error {
4 AuthenticationError,
6 ApiConnectionError,
8 InvalidRequestError,
10 RateLimitError,
13 NotFoundError,
15 ListenApiError,
17 Reqwest(reqwest::Error),
19 Json(serde_json::Error),
21}
22
23impl From<reqwest::Error> for Error {
24 fn from(e: reqwest::Error) -> Error {
25 Error::Reqwest(e)
26 }
27}
28
29impl From<serde_json::Error> for Error {
30 fn from(e: serde_json::Error) -> Error {
31 Error::Json(e)
32 }
33}
34
35impl std::error::Error for Error {
36 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
37 match *self {
38 Error::Reqwest(ref e) => Some(e),
39 Error::Json(ref e) => Some(e),
40 _ => None,
41 }
42 }
43}
44
45impl std::fmt::Display for Error {
46 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
47 match self {
48 Error::AuthenticationError => {
49 write!(f, "Wrong api key or your account is suspended.")
50 }
51 Error::ApiConnectionError => {
52 write!(f, "Fail to connect to API servers.")
53 }
54 Error::InvalidRequestError => {
55 write!(
56 f,
57 "Something wrong on your end (client side errors), e.g., missing required parameters."
58 )
59 }
60 Error::RateLimitError => {
61 write!(
62 f,
63 "For FREE plan, exceeding the quota limit; or for all plans, sending too many
64 requests too fast and exceeding the rate limit
65 - https://www.listennotes.com/api/faq/#faq17"
66 )
67 }
68 Error::NotFoundError => {
69 write!(f, "Endpoint not exist, or podcast / episode not exist.")
70 }
71 Error::ListenApiError => {
72 write!(f, "Something wrong on our end (unexpected server errors).")
73 }
74 Error::Reqwest(_) | Error::Json(_) => {
75 write!(f, "{}", self)
76 }
77 }
78 }
79}