1use std::{error::Error as ErrorTrait, env::VarError};
3use dotenv::Error as DotenvError;
4use serde_json::Error as SerdeJSONError;
5use reqwest::Error as ReqwestError;
6use std::{fmt::Display, convert::From};
8
9
10#[derive(Debug)]
11pub enum Error {
12 NoAPIKey,
13 VarError(VarError),
15 DotenvError(DotenvError),
17 SerdeJSONError(SerdeJSONError),
19 ReqwestError(ReqwestError),
21}
22
23impl Display for Error {
24 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25 match self {
26 Error::NoAPIKey => write!(f, "No API Key: No API key is defined."),
27 Error::VarError(e) => write!(f, "Var Error: {}", e.to_string()),
29 Error::DotenvError(e) => write!(f, "Dotenv Error: {}", e.to_string()),
31 Error::SerdeJSONError(e) => write!(f, "Serde JSON Error: {}", e.to_string()),
33 Error::ReqwestError(e) => write!(f, "Reqwest Error: {}", e.to_string()),
35 }
36 }
37}
38
39impl ErrorTrait for Error {}
40
41impl From<VarError> for Error {
42 fn from(value: VarError) -> Self {
43 Error::VarError(value)
44 }
45}
46
47impl From<DotenvError> for Error {
48 fn from(value: DotenvError) -> Self {
49 Error::DotenvError(value)
50 }
51}
52
53impl From<SerdeJSONError> for Error {
54 fn from(value: SerdeJSONError) -> Self {
55 Error::SerdeJSONError(value)
56 }
57}
58
59impl From<ReqwestError> for Error {
60 fn from(value: ReqwestError) -> Self {
61 Error::ReqwestError(value)
62 }
63}