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 #[cfg(feature = "persistence")]
28 #[error("db error: {0}")]
29 Sqlx(#[from] sqlx::Error),
30 #[error("parser error: {0}")]
32 Parser(String),
33}
34
35#[derive(Debug, thiserror::Error)]
37pub enum AuthError {
38 #[error("network error: {0}")]
40 Network(#[from] reqwest::Error),
41 #[error("io error: {0}")]
43 Io(#[from] io::Error),
44 #[error("json error: {0}")]
46 Json(#[from] serde_json::Error),
47 #[error("other error: {0}")]
49 Other(String),
50 #[error("bad credentials")]
52 BadCredentials,
53 #[error("unexpected http status: {0}")]
55 Unexpected(StatusCode),
56 #[error("rate limit exceeded")]
58 RateLimitExceeded,
59 #[error("missing {0} header in login response")]
66 MissingSessionToken(String),
67}
68
69impl From<Box<dyn std::error::Error + Send + Sync>> for AuthError {
70 #[cold]
71 fn from(e: Box<dyn std::error::Error + Send + Sync>) -> Self {
72 match e.downcast::<reqwest::Error>() {
73 Ok(req) => AuthError::Network(*req),
74 Err(e) => match e.downcast::<serde_json::Error>() {
75 Ok(js) => AuthError::Json(*js),
76 Err(e) => match e.downcast::<std::io::Error>() {
77 Ok(ioe) => AuthError::Io(*ioe),
78 Err(other) => AuthError::Other(other.to_string()),
79 },
80 },
81 }
82 }
83}
84
85impl From<Box<dyn std::error::Error>> for AuthError {
86 #[cold]
87 fn from(e: Box<dyn std::error::Error>) -> Self {
88 match e.downcast::<reqwest::Error>() {
89 Ok(req) => AuthError::Network(*req),
90 Err(e) => match e.downcast::<serde_json::Error>() {
91 Ok(js) => AuthError::Json(*js),
92 Err(e) => match e.downcast::<io::Error>() {
93 Ok(ioe) => AuthError::Io(*ioe),
94 Err(other) => AuthError::Other(other.to_string()),
95 },
96 },
97 }
98 }
99}
100
101impl From<AppError> for AuthError {
102 #[cold]
103 fn from(e: AppError) -> Self {
104 match e {
105 AppError::Network(e) => AuthError::Network(e),
106 AppError::Io(e) => AuthError::Io(e),
107 AppError::Json(e) => AuthError::Json(e),
108 AppError::Unexpected(s) => AuthError::Unexpected(s),
109 AppError::Auth(a) => a,
111 _ => AuthError::Other(e.to_string()),
112 }
113 }
114}
115
116#[derive(Debug, thiserror::Error)]
118pub enum AppError {
119 #[error("network error: {0}")]
121 Network(#[from] reqwest::Error),
122 #[error("io error: {0}")]
124 Io(#[from] io::Error),
125 #[error("json error: {0}")]
127 Json(#[from] serde_json::Error),
128 #[error("unexpected http status: {0}")]
130 Unexpected(StatusCode),
131 #[cfg(feature = "persistence")]
133 #[error("db error: {0}")]
134 Db(#[from] sqlx::Error),
135 #[error("unauthorized")]
137 Unauthorized,
138 #[error("oauth token expired")]
140 OAuthTokenExpired,
141 #[error("not found")]
143 NotFound,
144 #[error("rate limit exceeded")]
146 RateLimitExceeded,
147 #[error("historical data allowance exceeded, resets in {allowance_expiry} seconds")]
152 HistoricalDataAllowanceExceeded {
153 allowance_expiry: u64,
155 },
156 #[error("serialization error: {0}")]
158 SerializationError(String),
159 #[error("websocket error: {0}")]
161 WebSocketError(String),
162 #[error("deserialization error: {0}")]
164 Deserialization(String),
165 #[error("invalid input: {0}")]
167 InvalidInput(String),
168 #[error("auth error: {0}")]
175 Auth(#[from] AuthError),
176 #[error("generic error: {0}")]
178 Generic(String),
179}
180
181impl From<Box<dyn std::error::Error>> for AppError {
182 #[cold]
183 fn from(e: Box<dyn std::error::Error>) -> Self {
184 match e.downcast::<reqwest::Error>() {
185 Ok(req) => AppError::Network(*req),
186 Err(e) => match e.downcast::<serde_json::Error>() {
187 Ok(js) => AppError::Json(*js),
188 Err(e) => match e.downcast::<std::io::Error>() {
189 Ok(ioe) => AppError::Io(*ioe),
190 Err(other) => AppError::Generic(other.to_string()),
193 },
194 },
195 }
196 }
197}
198
199impl From<String> for AppError {
200 #[cold]
201 fn from(e: String) -> Self {
202 AppError::Generic(e)
203 }
204}
205
206#[cfg(feature = "streaming")]
207impl From<lightstreamer_rs::utils::LightstreamerError> for AppError {
208 #[cold]
209 fn from(e: lightstreamer_rs::utils::LightstreamerError) -> Self {
210 AppError::WebSocketError(e.to_string())
211 }
212}