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
60
61
62
63
64
65
66
67
68
69
70
use crate::response::ApiErrorResponse;
use std::error;
use std::fmt;
#[derive(Debug)]
pub enum ClientError {
General(String),
UnexpectedResponseType(String),
ApiError(ApiErrorResponse),
}
impl ClientError {
pub fn to_string(&self) -> String {
match self {
ClientError::General(error) => error.clone(),
ClientError::UnexpectedResponseType(error) => error.clone(),
ClientError::ApiError(error) => error.to_string(),
}
}
}
impl error::Error for ClientError {}
impl fmt::Display for ClientError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ClientError::General(error) => write!(f, "{}", error),
ClientError::UnexpectedResponseType(error) => write!(f, "{}", error),
ClientError::ApiError(error) => write!(f, "{}", error.to_string()),
}
}
}
impl From<String> for ClientError {
fn from(err: String) -> ClientError {
ClientError::General(err)
}
}
impl From<serde_json::Error> for ClientError {
fn from(err: serde_json::Error) -> Self {
ClientError::General(err.to_string())
}
}
impl From<serde_urlencoded::ser::Error> for ClientError {
fn from(err: serde_urlencoded::ser::Error) -> Self {
ClientError::General(err.to_string())
}
}
impl From<&str> for ClientError {
fn from(err: &str) -> ClientError {
ClientError::General(String::from(err))
}
}
impl From<reqwest::Error> for ClientError {
fn from(err: reqwest::Error) -> ClientError {
ClientError::General(err.to_string())
}
}