1use std::fmt;
2
3#[derive(Debug)]
4pub enum Error {
5 RequestError(reqwest::Error),
7 JsonError(serde_json::Error),
9 ApiError {
11 status: u16,
12 message: String,
13 },
14 AuthError(String),
16 InvalidInput(String),
18 Other(String),
20}
21
22impl std::error::Error for Error {}
23
24impl fmt::Display for Error {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 match self {
27 Error::RequestError(e) => write!(f, "Request error: {}", e),
28 Error::JsonError(e) => write!(f, "JSON error: {}", e),
29 Error::ApiError { status, message } => {
30 write!(f, "API error ({}): {}", status, message)
31 }
32 Error::AuthError(msg) => write!(f, "Authentication error: {}", msg),
33 Error::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
34 Error::Other(msg) => write!(f, "Error: {}", msg),
35 }
36 }
37}
38
39impl From<reqwest::Error> for Error {
40 fn from(err: reqwest::Error) -> Self {
41 Error::RequestError(err)
42 }
43}
44
45impl From<serde_json::Error> for Error {
46 fn from(err: serde_json::Error) -> Self {
47 Error::JsonError(err)
48 }
49}
50
51pub type Result<T> = std::result::Result<T, Error>;