1use reqwest::StatusCode;
7use std::io;
8
9#[deprecated(
18 since = "0.12.0",
19 note = "unused dead enum; use AppError (Network / Db / Deserialization) instead"
20)]
21#[derive(Debug, thiserror::Error)]
22pub enum FetchError {
23 #[error("network error: {0}")]
25 Reqwest(#[from] reqwest::Error),
26 #[error("db error: {0}")]
28 Sqlx(#[from] sqlx::Error),
29 #[error("parser error: {0}")]
31 Parser(String),
32}
33
34#[derive(Debug, thiserror::Error)]
36pub enum AuthError {
37 #[error("network error: {0}")]
39 Network(#[from] reqwest::Error),
40 #[error("io error: {0}")]
42 Io(#[from] io::Error),
43 #[error("json error: {0}")]
45 Json(#[from] serde_json::Error),
46 #[error("other error: {0}")]
48 Other(String),
49 #[error("bad credentials")]
51 BadCredentials,
52 #[error("unexpected http status: {0}")]
54 Unexpected(StatusCode),
55 #[error("rate limit exceeded")]
57 RateLimitExceeded,
58 #[error("missing {0} header in login response")]
65 MissingSessionToken(String),
66}
67
68impl From<Box<dyn std::error::Error + Send + Sync>> for AuthError {
69 #[cold]
70 fn from(e: Box<dyn std::error::Error + Send + Sync>) -> Self {
71 match e.downcast::<reqwest::Error>() {
72 Ok(req) => AuthError::Network(*req),
73 Err(e) => match e.downcast::<serde_json::Error>() {
74 Ok(js) => AuthError::Json(*js),
75 Err(e) => match e.downcast::<std::io::Error>() {
76 Ok(ioe) => AuthError::Io(*ioe),
77 Err(other) => AuthError::Other(other.to_string()),
78 },
79 },
80 }
81 }
82}
83
84impl From<Box<dyn std::error::Error>> for AuthError {
85 #[cold]
86 fn from(e: Box<dyn std::error::Error>) -> Self {
87 match e.downcast::<reqwest::Error>() {
88 Ok(req) => AuthError::Network(*req),
89 Err(e) => match e.downcast::<serde_json::Error>() {
90 Ok(js) => AuthError::Json(*js),
91 Err(e) => match e.downcast::<io::Error>() {
92 Ok(ioe) => AuthError::Io(*ioe),
93 Err(other) => AuthError::Other(other.to_string()),
94 },
95 },
96 }
97 }
98}
99
100impl From<AppError> for AuthError {
101 #[cold]
102 fn from(e: AppError) -> Self {
103 match e {
104 AppError::Network(e) => AuthError::Network(e),
105 AppError::Io(e) => AuthError::Io(e),
106 AppError::Json(e) => AuthError::Json(e),
107 AppError::Unexpected(s) => AuthError::Unexpected(s),
108 AppError::Auth(a) => a,
110 _ => AuthError::Other(e.to_string()),
111 }
112 }
113}
114
115#[derive(Debug, thiserror::Error)]
117pub enum AppError {
118 #[error("network error: {0}")]
120 Network(#[from] reqwest::Error),
121 #[error("io error: {0}")]
123 Io(#[from] io::Error),
124 #[error("json error: {0}")]
126 Json(#[from] serde_json::Error),
127 #[error("unexpected http status: {0}")]
129 Unexpected(StatusCode),
130 #[error("db error: {0}")]
132 Db(#[from] sqlx::Error),
133 #[error("unauthorized")]
135 Unauthorized,
136 #[error("oauth token expired")]
138 OAuthTokenExpired,
139 #[error("not found")]
141 NotFound,
142 #[error("rate limit exceeded")]
144 RateLimitExceeded,
145 #[error("historical data allowance exceeded, resets in {allowance_expiry} seconds")]
150 HistoricalDataAllowanceExceeded {
151 allowance_expiry: u64,
153 },
154 #[error("serialization error: {0}")]
156 SerializationError(String),
157 #[error("websocket error: {0}")]
159 WebSocketError(String),
160 #[error("deserialization error: {0}")]
162 Deserialization(String),
163 #[error("invalid input: {0}")]
165 InvalidInput(String),
166 #[error("auth error: {0}")]
173 Auth(#[from] AuthError),
174 #[error("generic error: {0}")]
176 Generic(String),
177}
178
179impl From<Box<dyn std::error::Error>> for AppError {
180 #[cold]
181 fn from(e: Box<dyn std::error::Error>) -> Self {
182 match e.downcast::<reqwest::Error>() {
183 Ok(req) => AppError::Network(*req),
184 Err(e) => match e.downcast::<serde_json::Error>() {
185 Ok(js) => AppError::Json(*js),
186 Err(e) => match e.downcast::<std::io::Error>() {
187 Ok(ioe) => AppError::Io(*ioe),
188 Err(other) => AppError::Generic(other.to_string()),
191 },
192 },
193 }
194 }
195}
196
197impl From<String> for AppError {
198 #[cold]
199 fn from(e: String) -> Self {
200 AppError::Generic(e)
201 }
202}
203
204impl From<lightstreamer_rs::utils::LightstreamerError> for AppError {
205 #[cold]
206 fn from(e: lightstreamer_rs::utils::LightstreamerError) -> Self {
207 AppError::WebSocketError(e.to_string())
208 }
209}