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 #[error("Obligation not engine-fulfillable: {0}")]
37 ObligationNotFulfillable(String),
38}
39
40impl AxonFlowError {
41 pub fn is_retryable(&self) -> bool {
42 match self {
43 AxonFlowError::HttpError(e) => e.is_timeout() || e.is_connect(),
44 AxonFlowError::ApiError { status, .. } => *status >= 500 || *status == 429,
45 AxonFlowError::RateLimited { .. } => true,
46 AxonFlowError::Unavailable(_) => true,
47 _ => false,
48 }
49 }
50
51 pub fn is_fail_open_eligible(&self) -> bool {
52 match self {
53 AxonFlowError::HttpError(e) => e.is_timeout() || e.is_connect(),
54 AxonFlowError::ApiError { status, .. } => *status >= 500 || *status == 429,
55 AxonFlowError::RateLimited { .. } => true,
56 AxonFlowError::Unavailable(_) => true,
57 _ => false,
58 }
59 }
60}