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
71
72
73
74
75
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("Treated resource as local file, but file does not exist ({0})")]
ResourceNotFound(String),
#[error("Unable to parse resource URL ({0})")]
InvalidUrl(String),
#[error("Offline mode is enabled but no cached versions of resouce exist ({0})")]
NoCachedVersions(String),
#[error("Cache is corrupted ({0})")]
CacheCorrupted(String),
#[error("Extracting archive failed ({0})")]
ExtractionError(String),
#[error("An IO error occurred")]
IoError(#[from] std::io::Error),
#[error("HTTP response had status code {0}")]
HttpStatusError(u16),
#[error("HTTP response timeout out")]
HttpTimeoutError,
#[error("HTTP builder error")]
HttpBuilderError,
#[error("An HTTP error occurred")]
HttpError,
}
impl Error {
pub(crate) fn is_retriable(&self) -> bool {
match self {
Error::HttpTimeoutError => true,
Error::HttpStatusError(status_code) => matches!(status_code, 502 | 503 | 504),
_ => false,
}
}
}
impl From<reqwest::Error> for Error {
fn from(err: reqwest::Error) -> Error {
if err.is_status() {
Error::HttpStatusError(err.status().unwrap().as_u16())
} else if err.is_timeout() {
Error::HttpTimeoutError
} else if err.is_builder() {
Error::HttpBuilderError
} else {
Error::HttpError
}
}
}