use std::{error::Error as ErrorTrait, env::VarError};
use dotenv::Error as DotenvError;
use serde_json::Error as SerdeJSONError;
use reqwest::Error as ReqwestError;
use std::{fmt::Display, convert::From};
#[derive(Debug)]
pub enum Error {
NoAPIKey,
VarError(VarError),
DotenvError(DotenvError),
SerdeJSONError(SerdeJSONError),
ReqwestError(ReqwestError),
}
impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::NoAPIKey => write!(f, "No API Key: No API key is defined."),
Self::VarError(e) => write!(f, "Var Error: {}", e.to_string()),
Self::DotenvError(e) => write!(f, "Dotenv Error: {}", e.to_string()),
Self::SerdeJSONError(e) => write!(f, "Serde JSON Error: {}", e.to_string()),
Self::ReqwestError(e) => write!(f, "Reqwest Error: {}", e.to_string()),
}
}
}
impl ErrorTrait for Error {}
impl From<VarError> for Error {
fn from(value: VarError) -> Self {
Self::VarError(value)
}
}
impl From<DotenvError> for Error {
fn from(value: DotenvError) -> Self {
Self::DotenvError(value)
}
}
impl From<SerdeJSONError> for Error {
fn from(value: SerdeJSONError) -> Self {
Self::SerdeJSONError(value)
}
}
impl From<ReqwestError> for Error {
fn from(value: ReqwestError) -> Self {
Self::ReqwestError(value)
}
}