1use std::fmt;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Debug, thiserror::Error)]
10pub enum Error {
11 #[error("Configuration error: {0}")]
13 Config(String),
14
15 #[error("HTTP request error: {0}")]
17 Http(#[from] reqwest::Error),
18
19 #[error("JSON error: {0}")]
21 Json(#[from] serde_json::Error),
22
23 #[error("I/O error: {0}")]
25 Io(#[from] std::io::Error),
26
27 #[error("Cache error: {0}")]
29 Cache(String),
30
31 #[error("Statistics error: {0}")]
33 Statistics(String),
34
35 #[error("API error: {0}")]
37 Api(String),
38
39 #[error("Error: {0}")]
41 Other(#[from] anyhow::Error),
42}
43
44impl Error {
45 pub fn config<T: fmt::Display>(msg: T) -> Self {
47 Self::Config(msg.to_string())
48 }
49
50 pub fn cache<T: fmt::Display>(msg: T) -> Self {
52 Self::Cache(msg.to_string())
53 }
54
55 pub fn statistics<T: fmt::Display>(msg: T) -> Self {
57 Self::Statistics(msg.to_string())
58 }
59
60 pub fn api<T: fmt::Display>(msg: T) -> Self {
62 Self::Api(msg.to_string())
63 }
64}