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