1use bytes::Bytes;
2use reqwest::StatusCode;
3use std::fmt::{Debug, Formatter};
4use std::{error, fmt};
5
6#[derive(Debug)]
7pub enum Error {
8 ReqwestError(reqwest::Error),
10
11 RequestFailed {
13 bytes: Bytes,
14 status_code: StatusCode,
15 },
16
17 SerdeError(serde_json::Error),
19}
20
21impl error::Error for Error {}
22
23impl fmt::Display for Error {
24 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
25 match self {
26 Self::ReqwestError(e) => std::fmt::Display::fmt(&e, f),
27 Self::RequestFailed { bytes, status_code } => {
28 let text = String::from_utf8_lossy(bytes);
29 write!(f, "{status_code}: {text}")
30 }
31 Self::SerdeError(e) => write!(f, "{e}"),
32 }
33 }
34}
35
36impl From<reqwest::Error> for Error {
37 fn from(e: reqwest::Error) -> Self {
38 Self::ReqwestError(e)
39 }
40}
41
42impl From<serde_json::Error> for Error {
43 fn from(e: serde_json::Error) -> Self {
44 Self::SerdeError(e)
45 }
46}