1use std::fmt;
2
3#[derive(Debug)]
5pub enum Error {
6 Http(reqwest::Error),
8 Api { status: u16, body: String },
10}
11
12impl fmt::Display for Error {
13 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14 match self {
15 Error::Http(e) => write!(f, "HTTP error: {e}"),
16 Error::Api { status, body } => write!(f, "API error (HTTP {status}): {body}"),
17 }
18 }
19}
20
21impl std::error::Error for Error {
22 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
23 match self {
24 Error::Http(e) => Some(e),
25 Error::Api { .. } => None,
26 }
27 }
28}
29
30impl From<reqwest::Error> for Error {
31 fn from(e: reqwest::Error) -> Self {
32 Error::Http(e)
33 }
34}