use thiserror::Error;
#[derive(Debug, Error)]
pub enum IicpError {
#[error("network error: {0}")]
Http(#[from] reqwest::Error),
#[error("[{code}] {message} (HTTP {status})")]
Protocol {
code: String,
message: String,
status: u16,
},
#[error("SDK-03: invalid intent URN: {0}")]
InvalidIntent(String),
#[error("SDK-04: timeout_ms must be ≤ 120000; got {0}")]
TimeoutTooLarge(u64),
#[error("no nodes available for intent {intent}")]
NoNodes { intent: String },
#[error("serialization error: {0}")]
Serde(#[from] serde_json::Error),
#[error("node error: {0}")]
Node(String),
}
impl IicpError {
pub fn is_transient(&self) -> bool {
matches!(
self,
IicpError::Protocol {
status: 429 | 502 | 503 | 504,
..
} | IicpError::Http(_)
)
}
}
pub type Result<T> = std::result::Result<T, IicpError>;