use std::fmt;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("Configuration error: {0}")]
Config(String),
#[error("HTTP request error: {0}")]
Http(#[from] reqwest::Error),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("Cache error: {0}")]
Cache(String),
#[error("Statistics error: {0}")]
Statistics(String),
#[error("API error: {0}")]
Api(String),
#[error("Error: {0}")]
Other(#[from] anyhow::Error),
}
impl Error {
pub fn config<T: fmt::Display>(msg: T) -> Self {
Self::Config(msg.to_string())
}
pub fn cache<T: fmt::Display>(msg: T) -> Self {
Self::Cache(msg.to_string())
}
pub fn statistics<T: fmt::Display>(msg: T) -> Self {
Self::Statistics(msg.to_string())
}
pub fn api<T: fmt::Display>(msg: T) -> Self {
Self::Api(msg.to_string())
}
}