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
use reqwest::header::InvalidHeaderValue;
use custom_error::custom_error;
pub type Result<T> = std::result::Result<T, Error>;
custom_error! { #[derive(PartialEq)] pub Error
AboveLimit{option: String, val: u64, max: u64} =
"{option}:{val} is above the maximum value allowed in this context ({max})",
Http{url: String, code: u16, reason: Option<String>} = @{
format!("HTTP error on URL \"{}\": {}{}", url, code, match reason {
Some(reason) => format!(": {}", reason),
None => match code {
200 => String::from(" OK: Request was successful"),
403 => String::from(" Forbidden: Access denied. May indicate that your request lacks a User-Agent header."),
404 => String::from(" Not Found"),
412 => String::from(" Precondition failed"),
420 => String::from(" Invalid Record: Record could not be saved"),
421 => String::from(" User Throttled: User is throttled, try again later"),
422 => String::from(" Locked: The resource is locked and cannot be modified"),
423 => String::from(" Already Exists: Resource already exists"),
424 => String::from(" Invalid Parameters: The given parameters were invalid"),
500 => String::from(" Internal Server Error: Some unknown error occurred on the server"),
502 => String::from(" Bad Gateway: A gateway server received an invalid response from the e621 servers"),
503 => String::from(" Service Unavailable: Server cannot currently handle the request or you have exceeded the request rate limit. Try again later or decrease your rate of requests."),
520 => String::from(" Unknown Error: Unexpected server response which violates protocol"),
522 => String::from(" Origin Connection Time-out: CloudFlare's attempt to connect to the e621 servers timed out"),
524 => String::from(" Origin Connection Time-out: A connection was established between CloudFlare and the e621 servers, but it timed out before an HTTP response was received"),
525 => String::from(" SSL Handshake Failed: The SSL handshake between CloudFlare and the e621 servers failed"),
_ => String::new(),
},
})
},
Serial{desc: String} = "Serialization error: {desc}",
Deserialization{desc: String} = "Deserialization error: {desc}",
CannotSendRequest{desc: String} = "Couldn't send request: {desc}",
CannotCreateClient{desc: String} = "Couldn't create client: {desc}",
InvalidHeaderValue{desc: String} = "Invalid header value",
PostNotFound{id: u64} = "Post #{id} not found",
}
impl From<InvalidHeaderValue> for Error {
fn from(e: InvalidHeaderValue) -> Error {
Error::InvalidHeaderValue {
desc: format!("Invalid header value: {}", e),
}
}
}
impl From<serde_json::error::Error> for Error {
fn from(e: serde_json::error::Error) -> Error {
Error::Deserialization {
desc: format!("{:#?}", e),
}
}
}