1use thiserror::Error;
3
4#[derive(Debug, Error)]
6pub enum IicpError {
7 #[error("network error: {0}")]
9 Http(#[from] reqwest::Error),
10
11 #[error("[{code}] {message} (HTTP {status})")]
13 Protocol {
14 code: String,
15 message: String,
16 status: u16,
17 },
18
19 #[error("SDK-03: invalid intent URN: {0}")]
21 InvalidIntent(String),
22
23 #[error("SDK-04: timeout_ms must be ≤ 120000; got {0}")]
25 TimeoutTooLarge(u64),
26
27 #[error("no nodes available for intent {intent}")]
29 NoNodes { intent: String },
30
31 #[error("serialization error: {0}")]
33 Serde(#[from] serde_json::Error),
34
35 #[error("node error: {0}")]
37 Node(String),
38}
39
40impl IicpError {
41 pub fn is_transient(&self) -> bool {
43 matches!(
44 self,
45 IicpError::Protocol {
46 status: 429 | 502 | 503 | 504,
47 ..
48 } | IicpError::Http(_)
49 )
50 }
51}
52
53pub type Result<T> = std::result::Result<T, IicpError>;