1use std::fmt;
2
3#[derive(Debug)]
5pub enum Error {
6 Auth {
8 status_code: u16,
9 message: String,
10 },
11 Api {
13 status_code: u16,
14 message: String,
15 body: String,
16 },
17 Network(reqwest::Error),
19}
20
21impl fmt::Display for Error {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 match self {
24 Error::Auth {
25 status_code,
26 message,
27 } => write!(f, "auth error {}: {}", status_code, message),
28 Error::Api {
29 status_code,
30 message,
31 ..
32 } => write!(f, "API error {}: {}", status_code, message),
33 Error::Network(e) => write!(f, "network error: {}", e),
34 }
35 }
36}
37
38impl std::error::Error for Error {
39 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
40 match self {
41 Error::Network(e) => Some(e),
42 _ => None,
43 }
44 }
45}
46
47impl From<reqwest::Error> for Error {
48 fn from(e: reqwest::Error) -> Self {
49 Error::Network(e)
50 }
51}