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
76
77
78
79
80
81
82
83
84
85
use reqwest::header::InvalidHeaderValue;
#[derive(Debug)]
pub enum APIError {
ClientNotReady,
FailedGetIP(String),
LoginFailed(String),
RequestFailed(reqwest::Error),
InvalidHeader(InvalidHeaderValue),
BadUrl(url::ParseError),
BadParameters,
AccessDenied,
NotFound,
RequestThrottled,
UnknownError,
InMaintenance,
BadResponse(String, reqwest::StatusCode),
InvalidParameters(String),
InvalidTag(String),
EventFailure(String),
}
impl std::error::Error for APIError {}
impl From<logic_long::LogicLongError> for APIError {
fn from(e: logic_long::LogicLongError) -> Self {
Self::InvalidTag(e.to_string())
}
}
impl From<reqwest::Error> for APIError {
fn from(e: reqwest::Error) -> Self {
Self::RequestFailed(e)
}
}
impl From<url::ParseError> for APIError {
fn from(e: url::ParseError) -> Self {
Self::BadUrl(e)
}
}
impl From<InvalidHeaderValue> for APIError {
fn from(e: InvalidHeaderValue) -> Self {
Self::InvalidHeader(e)
}
}
impl std::fmt::Display for APIError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::ClientNotReady => write!(f, "Client not ready"),
Self::FailedGetIP(e) => write!(f, "Failed to get IP address: {e}"),
Self::LoginFailed(e) => write!(f, "Failed to login: {e}"),
Self::RequestFailed(e) => write!(f, "Request failed: {e}"),
Self::InvalidHeader(e) => write!(f, "Invalid header: {e}"),
Self::BadUrl(e) => write!(f, "Bad URL: {e}"),
Self::BadParameters => write!(f, "Bad parameters"),
Self::AccessDenied => write!(f, "Access denied"),
Self::NotFound => write!(f, "Not found"),
Self::RequestThrottled => write!(f, "Request throttled"),
Self::UnknownError => write!(f, "Unknown error"),
Self::InMaintenance => write!(f, "In maintenance"),
Self::BadResponse(e, s) => write!(f, "Bad response: {e} ({s})"),
Self::InvalidParameters(e) => write!(f, "Invalid parameters: {e}"),
Self::InvalidTag(e) => write!(f, "Invalid tag: {e}"),
Self::EventFailure(e) => write!(f, "Event failure: {e}"),
}
}
}