1use crate::prelude::*;
2
3#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
5#[serde(rename_all = "snake_case")]
6pub enum CantDoReason {
7 InvalidSignature,
9 InvalidTradeIndex,
11 InvalidAmount,
13 InvalidInvoice,
15 InvalidPaymentRequest,
17 InvalidPeer,
19 InvalidRating,
21 InvalidTextMessage,
23 InvalidOrderKind,
25 InvalidOrderStatus,
27 InvalidPubkey,
29 InvalidParameters,
31 OrderAlreadyCanceled,
33 CantCreateUser,
35 IsNotYourOrder,
37 NotAllowedByStatus,
39 OutOfRangeFiatAmount,
41 OutOfRangeSatsAmount,
43 IsNotYourDispute,
45 DisputeTakenByAdmin,
47 NotAuthorized,
49 DisputeCreationError,
51 NotFound,
53 InvalidDisputeStatus,
55 InvalidAction,
57 PendingOrderExists,
59 InvalidFiatCurrency,
61 TooManyRequests,
63}
64
65#[derive(Debug, PartialEq, Eq)]
66pub enum ServiceError {
67 NostrError(String),
68 ParsingInvoiceError,
69 ParsingNumberError,
70 InvoiceExpiredError,
71 InvoiceInvalidError,
72 MinExpirationTimeError,
73 MinAmountError,
74 WrongAmountError,
75 NoAPIResponse,
76 NoCurrency,
77 MalformedAPIRes,
78 NegativeAmount,
79 LnAddressParseError,
80 LnAddressWrongAmount,
81 LnPaymentError(String),
82 LnNodeError(String),
83 InvalidOrderId,
84 DbAccessError(String),
85 InvalidPubkey,
86 HoldInvoiceError(String),
87 UpdateOrderStatusError,
88 InvalidOrderStatus,
89 InvalidOrderKind,
90 DisputeAlreadyExists,
91 DisputeEventError,
92 InvalidRating,
93 InvalidRatingValue,
94 MessageSerializationError,
95 InvalidDisputeId,
96 InvalidDisputeStatus,
97 InvalidPayload,
98 UnexpectedError(String),
99 EnvVarError(String),
100 IOError(String),
101 EncryptionError(String),
102 DecryptionError(String),
103}
104
105#[derive(Debug, PartialEq, Eq)]
106pub enum MostroError {
107 MostroInternalErr(ServiceError),
108 MostroCantDo(CantDoReason),
109}
110
111impl std::error::Error for MostroError {}
112
113impl std::fmt::Display for MostroError {
114 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
115 match self {
116 MostroError::MostroInternalErr(m) => write!(f, "Error caused by {}", m),
117 MostroError::MostroCantDo(m) => write!(f, "Sending cantDo message to user for {:?}", m),
118 }
119 }
120}
121
122impl std::fmt::Display for ServiceError {
123 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
124 match self {
125 ServiceError::ParsingInvoiceError => write!(f, "Incorrect invoice"),
126 ServiceError::ParsingNumberError => write!(f, "Error parsing the number"),
127 ServiceError::InvoiceExpiredError => write!(f, "Invoice has expired"),
128 ServiceError::MinExpirationTimeError => write!(f, "Minimal expiration time on invoice"),
129 ServiceError::InvoiceInvalidError => write!(f, "Invoice is invalid"),
130 ServiceError::MinAmountError => write!(f, "Minimal payment amount"),
131 ServiceError::WrongAmountError => write!(f, "The amount on this invoice is wrong"),
132 ServiceError::NoAPIResponse => write!(f, "Price API not answered - retry"),
133 ServiceError::NoCurrency => write!(f, "Currency requested is not present in the exchange list, please specify a fixed rate"),
134 ServiceError::MalformedAPIRes => write!(f, "Malformed answer from exchange quoting request"),
135 ServiceError::NegativeAmount => write!(f, "Negative amount is not valid"),
136 ServiceError::LnAddressWrongAmount => write!(f, "Ln address need amount of 0 sats - please check your order"),
137 ServiceError::LnAddressParseError => write!(f, "Ln address parsing error - please check your address"),
138 ServiceError::LnPaymentError(e) => write!(f, "Lightning payment failure cause: {}",e),
139 ServiceError::LnNodeError(e) => write!(f, "Lightning node connection failure caused by: {}",e),
140 ServiceError::InvalidOrderId => write!(f, "Order id not present in database"),
141 ServiceError::InvalidPubkey => write!(f, "Invalid pubkey"),
142 ServiceError::DbAccessError(e) => write!(f, "Error in database access: {}",e),
143 ServiceError::HoldInvoiceError(e) => write!(f, "Error holding invoice: {}",e),
144 ServiceError::UpdateOrderStatusError => write!(f, "Error updating order status"),
145 ServiceError::InvalidOrderStatus => write!(f, "Invalid order status"),
146 ServiceError::InvalidOrderKind => write!(f, "Invalid order kind"),
147 ServiceError::DisputeAlreadyExists => write!(f, "Dispute already exists"),
148 ServiceError::DisputeEventError => write!(f, "Error publishing dispute event"),
149 ServiceError::NostrError(e) => write!(f, "Error in nostr: {}",e),
150 ServiceError::InvalidRating => write!(f, "Invalid rating message"),
151 ServiceError::InvalidRatingValue => write!(f, "Invalid rating value"),
152 ServiceError::MessageSerializationError => write!(f, "Error serializing message"),
153 ServiceError::InvalidDisputeId => write!(f, "Invalid dispute id"),
154 ServiceError::InvalidDisputeStatus => write!(f, "Invalid dispute status"),
155 ServiceError::InvalidPayload => write!(f, "Invalid payload"),
156 ServiceError::UnexpectedError(e) => write!(f, "Unexpected error: {}", e),
157 ServiceError::EnvVarError(e) => write!(f, "Environment variable error: {}", e),
158 ServiceError::IOError(e) => write!(f, "IO error: {}", e),
159 ServiceError::EncryptionError(e) => write!(f, "Encryption error: {}", e),
160 ServiceError::DecryptionError(e) => write!(f, "Decryption error: {}", e),
161 }
162 }
163}