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
use serde::{Deserialize, Serialize};
use std::fmt;
use url::ParseError;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ErrorInformation {
pub error: String,
#[serde(default)]
pub message: String,
}
#[derive(thiserror::Error, Debug)]
pub enum ClientError<E>
where
E: std::error::Error + Send + Sync + 'static,
{
#[error("client error: {0}")]
Client(#[from] Box<E>),
#[error("request error: {0}")]
Request(String),
#[error("service error: {0}")]
Service(ErrorInformation),
#[error("token error: {0}")]
Token(#[source] Box<dyn std::error::Error + Send + Sync>),
#[error("Url parse error")]
Url(#[from] ParseError),
#[error("Syntax error: {0}")]
Syntax(#[from] serde_json::error::Error),
}
#[cfg(feature = "reqwest")]
impl From<reqwest::Error> for ClientError<reqwest::Error> {
fn from(err: reqwest::Error) -> Self {
ClientError::Client(Box::new(err))
}
}
impl fmt::Display for ErrorInformation {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}: {}", self.error, self.message)
}
}