Skip to main content

useragent_coinpayment/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub enum CoinPaymentErrCode {
5    BalanceLow,
6    Denied,
7    BadCoins,
8    SnipedCoins,
9    PurseNotFound,
10    ReceivableNotFound,
11    UnsupportedChannel,
12    UserAgentCapabilityUnavailable,
13    Internal,
14}
15
16impl CoinPaymentErrCode {
17    pub fn as_str(self) -> &'static str {
18        match self {
19            Self::BalanceLow => "balanceLow",
20            Self::Denied => "denied",
21            Self::BadCoins => "badCoins",
22            Self::SnipedCoins => "snipedCoins",
23            Self::PurseNotFound => "purseNotFound",
24            Self::ReceivableNotFound => "receivableNotFound",
25            Self::UnsupportedChannel => "unsupportedChannel",
26            Self::UserAgentCapabilityUnavailable => "userAgentCapabilityUnavailable",
27            Self::Internal => "internal",
28        }
29    }
30}
31
32#[derive(Debug, Error)]
33#[error("{code:?}: {message}")]
34pub struct CoinPaymentError {
35    pub code: CoinPaymentErrCode,
36    pub message: String,
37}
38
39impl CoinPaymentError {
40    pub fn new(code: CoinPaymentErrCode, message: impl Into<String>) -> Self {
41        Self {
42            code,
43            message: message.into(),
44        }
45    }
46
47    pub fn internal(message: impl Into<String>) -> Self {
48        Self::new(CoinPaymentErrCode::Internal, message)
49    }
50}
51
52pub type Result<T> = std::result::Result<T, CoinPaymentError>;