1use thiserror::Error;
5
6#[derive(Error, Debug)]
7pub enum Error {
8 #[error("Authentication failed: {0}")]
9 AuthenticationFailed(String),
10
11 #[error("Rate limited — retry after {retry_after_secs}s")]
12 RateLimit { retry_after_secs: u64 },
13
14 #[error("Memory not found: {0}")]
15 NotFound(String),
16
17 #[error("Validation error: {0}")]
18 Validation(String),
19
20 #[error("Server error: {status} {message}")]
21 Server { status: u16, message: String },
22
23 #[error("Network error: {0}")]
24 Network(#[from] reqwest::Error),
25
26 #[error("Serialization error: {0}")]
27 Serialization(#[from] serde_json::Error),
28
29 #[error("Configuration error: {0}")]
30 Config(String),
31
32 #[error("Circuit open — memory service unavailable, will retry in {cooldown_secs}s")]
33 CircuitOpen { cooldown_secs: u64 },
34}
35
36impl Error {
37 pub fn is_transient(&self) -> bool {
39 matches!(
40 self,
41 Error::RateLimit { .. }
42 | Error::Network(_)
43 | Error::Server {
44 status: 500..=599,
45 ..
46 }
47 )
48 }
49
50 pub fn is_swallowable(&self) -> bool {
59 matches!(
60 self,
61 Error::RateLimit { .. }
62 | Error::Network(_)
63 | Error::Server {
64 status: 500..=599,
65 ..
66 }
67 | Error::CircuitOpen { .. }
68 | Error::Serialization(_)
69 )
70 }
71}