forked from Echo-Mirror-Butler/echomirror-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.rs
More file actions
67 lines (52 loc) · 1.99 KB
/
Copy patherror.rs
File metadata and controls
67 lines (52 loc) · 1.99 KB
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 thiserror::Error;
pub type Result<T> = std::result::Result<T, EchoMirrorError>;
#[derive(Debug, Error)]
pub enum EchoMirrorError {
#[error("HTTP error {status}: {message}")]
Http { status: u16, message: String },
#[error("Authentication failed: {0}")]
Auth(String),
#[error("Authentication token expired")]
AuthExpired,
#[error("Rate limit exceeded — retry after {retry_after_secs}s")]
RateLimit { retry_after_secs: u64 },
#[error("Network error: {0}")]
Network(#[from] reqwest::Error),
#[error("Serialization error: {0}")]
Serialization(#[from] serde_json::Error),
#[error("Invalid response from server: {0}")]
InvalidResponse(String),
#[error("Stellar error: {0}")]
Stellar(String),
#[error("Blockchain sync error: {0}")]
Sync(String),
#[error("Invalid configuration: {0}")]
Config(String),
#[error("Not found: {0}")]
NotFound(String),
#[error("{0}")]
Other(String),
}
impl EchoMirrorError {
/// Returns true if this error is retryable (transient failures)
pub fn is_retryable(&self) -> bool {
match self {
// Network errors are retryable (connection issues, timeouts, etc.)
EchoMirrorError::Network(_) => true,
// 5xx server errors are retryable
EchoMirrorError::Http { status, .. } if *status >= 500 => true,
// 4xx client errors are NOT retryable
EchoMirrorError::Http { status, .. } if *status >= 400 && *status < 500 => false,
// Rate limit errors are retryable (with backoff)
EchoMirrorError::RateLimit { .. } => true,
// Auth expired is retryable after token refresh
EchoMirrorError::AuthExpired => true,
// Other errors are not retryable
_ => false,
}
}
/// Returns true if this error indicates the auth token should be refreshed
pub fn is_auth_expired(&self) -> bool {
matches!(self, EchoMirrorError::AuthExpired)
}
}