Skip to main content

haima_core/
error.rs

1//! Error types for Haima.
2
3use thiserror::Error;
4
5pub type HaimaResult<T> = Result<T, HaimaError>;
6
7#[derive(Debug, Error)]
8pub enum HaimaError {
9    #[error("wallet error: {0}")]
10    Wallet(String),
11
12    #[error("payment denied: {0}")]
13    PaymentDenied(String),
14
15    #[error("settlement failed: {0}")]
16    SettlementFailed(String),
17
18    #[error("facilitator error: {0}")]
19    Facilitator(String),
20
21    #[error("insufficient balance: need {needed} micro-credits, have {available}")]
22    InsufficientBalance { needed: i64, available: i64 },
23
24    #[error("amount exceeds policy cap: {amount} > {cap} micro-credits")]
25    ExceedsPolicyCap { amount: i64, cap: i64 },
26
27    #[error("unsupported chain: {0}")]
28    UnsupportedChain(String),
29
30    #[error("unsupported payment scheme: {0}")]
31    UnsupportedScheme(String),
32
33    #[error("protocol error: {0}")]
34    Protocol(String),
35
36    #[error("serialization error: {0}")]
37    Serialization(#[from] serde_json::Error),
38
39    #[error("http error: {0}")]
40    Http(String),
41
42    #[error("crypto error: {0}")]
43    Crypto(String),
44
45    #[error("insufficient credit: {reason}")]
46    InsufficientCredit { reason: String },
47
48    // -- Insurance errors --
49    #[error("policy not found: {0}")]
50    PolicyNotFound(String),
51
52    #[error("policy not active: {policy_id} is {status}")]
53    PolicyNotActive { policy_id: String, status: String },
54
55    #[error("claim exceeds coverage: claimed {claimed} > remaining {remaining} micro-USD")]
56    ClaimExceedsCoverage { claimed: i64, remaining: i64 },
57
58    #[error("agent not insurable: {reason}")]
59    NotInsurable { reason: String },
60
61    #[error("quote expired: {quote_id}")]
62    QuoteExpired { quote_id: String },
63
64    #[error("quote not found: {0}")]
65    QuoteNotFound(String),
66
67    #[error("product not found: {0}")]
68    ProductNotFound(String),
69
70    #[error("pool reserves insufficient: need {needed}, have {available} micro-USD")]
71    PoolReservesInsufficient { needed: i64, available: i64 },
72
73    #[error("provider not found: {0}")]
74    ProviderNotFound(String),
75
76    #[error("claim not found: {0}")]
77    ClaimNotFound(String),
78}