axonflow_sdk_rust/
error.rs1use crate::types::decisions::RateLimitEnvelope;
2use thiserror::Error;
3
4#[derive(Error, Debug)]
5pub enum AxonFlowError {
6 #[error("HTTP request failed: {0}")]
7 HttpError(#[from] reqwest::Error),
8 #[error("Serialization/Deserialization failed: {0}")]
9 SerdeError(#[from] serde_json::Error),
10 #[error("API error ({status}): {message}")]
11 ApiError { status: u16, message: String },
12 #[error("Rate limited (tier={}, limit_type={}): {}", .envelope.tier, .envelope.limit_type, .envelope.error)]
20 RateLimited { envelope: Box<RateLimitEnvelope> },
21 #[error("Configuration error: {0}")]
22 ConfigError(String),
23 #[error("AxonFlow platform is unavailable: {0}")]
24 Unavailable(String),
25}
26
27impl AxonFlowError {
28 pub fn is_retryable(&self) -> bool {
29 match self {
30 AxonFlowError::HttpError(e) => e.is_timeout() || e.is_connect(),
31 AxonFlowError::ApiError { status, .. } => *status >= 500 || *status == 429,
32 AxonFlowError::RateLimited { .. } => true,
33 AxonFlowError::Unavailable(_) => true,
34 _ => false,
35 }
36 }
37
38 pub fn is_fail_open_eligible(&self) -> bool {
39 match self {
40 AxonFlowError::HttpError(e) => e.is_timeout() || e.is_connect(),
41 AxonFlowError::ApiError { status, .. } => *status >= 500 || *status == 429,
42 AxonFlowError::RateLimited { .. } => true,
43 AxonFlowError::Unavailable(_) => true,
44 _ => false,
45 }
46 }
47}