-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.rs
40 lines (34 loc) · 945 Bytes
/
error.rs
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
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("{0}")]
ClientCreation(String),
#[error("Remote responded with status code {0:?} with reason {1}")]
Http(Option<u16>, String),
#[error("{0}")]
Decode(String),
#[error("{0}")]
OtherHttp(String),
}
impl From<reqwest::Error> for Error {
fn from(err: reqwest::Error) -> Self {
if err.is_builder() {
return Self::ClientCreation(err.to_string());
}
if err.is_decode() {
return Self::Decode(err.to_string());
}
if err.is_status() {
return Self::Http(
err.status().map(|status_code| status_code.as_u16()),
err.to_string(),
);
}
Self::OtherHttp(err.to_string())
}
}
impl From<url::ParseError> for Error {
fn from(err: url::ParseError) -> Self {
Self::OtherHttp(format!("{err:?}"))
}
}