1use reqwest::StatusCode;
2use std::error::Error;
3use std::fmt;
4
5#[derive(Debug)]
6pub struct VndbApiError {
7 pub status: Option<StatusCode>,
8 pub message: String,
9}
10
11impl Error for VndbApiError {}
12
13impl fmt::Display for VndbApiError {
14 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15 write!(f, "Error ({:#?}): {:#?}", self.status, self.message)
16 }
17}
18
19impl VndbApiError {
20 pub fn new(status: StatusCode, message: String) -> Self {
21 Self {
22 status: Some(status),
23 message,
24 }
25 }
26}
27
28impl From<reqwest::Error> for VndbApiError {
29 fn from(err: reqwest::Error) -> Self {
30 let status = err.status();
31 let message = format!("Reqwest error: {}", err);
32
33 Self { status, message }
34 }
35}