1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use std::error::Error as StdError;
use std::fmt;
use reqwest::{ Error, Response, StatusCode };
pub type Result<T> = std::result::Result<T, RiotApiError>;
#[derive(Debug)]
pub struct RiotApiError {
reqwest_error: Error,
retries: u8,
response: Option<Response>,
status_code: Option<StatusCode>,
}
impl RiotApiError {
pub(crate) fn new(reqwest_error: Error, retries: u8, response: Option<Response>, status_code: Option<StatusCode>) -> Self {
Self {
reqwest_error: reqwest_error,
retries: retries,
response: response,
status_code: status_code,
}
}
pub fn source_reqwest_error(&self) -> &Error {
&self.reqwest_error
}
pub fn retries(&self) -> u8 {
self.retries
}
pub fn response(&self) -> Option<&Response> {
self.response.as_ref()
}
pub fn status_code(&self) -> Option<StatusCode> {
self.status_code
}
}
impl fmt::Display for RiotApiError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:#?}", self)
}
}
impl StdError for RiotApiError {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
Some(&self.reqwest_error)
}
}