use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("Authentication failed: {0}")]
AuthenticationFailed(String),
#[error("Rate limited — retry after {retry_after_secs}s")]
RateLimit { retry_after_secs: u64 },
#[error("Memory not found: {0}")]
NotFound(String),
#[error("Validation error: {0}")]
Validation(String),
#[error("Server error: {status} {message}")]
Server { status: u16, message: String },
#[error("Network error: {0}")]
Network(#[from] reqwest::Error),
#[error("Serialization error: {0}")]
Serialization(#[from] serde_json::Error),
#[error("Configuration error: {0}")]
Config(String),
#[error("Circuit open — memory service unavailable, will retry in {cooldown_secs}s")]
CircuitOpen { cooldown_secs: u64 },
}
impl Error {
pub fn is_transient(&self) -> bool {
matches!(
self,
Error::RateLimit { .. }
| Error::Network(_)
| Error::Server {
status: 500..=599,
..
}
)
}
pub fn is_swallowable(&self) -> bool {
matches!(
self,
Error::RateLimit { .. }
| Error::Network(_)
| Error::Server {
status: 500..=599,
..
}
| Error::CircuitOpen { .. }
| Error::Serialization(_)
)
}
}