1use thiserror::Error;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum PayErrorCode {
6 HttpTransport,
8 HttpStatus,
10 ProtocolMalformed,
12 ProtocolUnknown,
14 WalletNotFound,
16 SigningFailed,
18 UnsupportedChain,
20 DiscoveryFailed,
22 InvalidInput,
24}
25
26#[derive(Debug, Error)]
27#[error("[{code:?}] {message}")]
28pub struct PayError {
29 pub code: PayErrorCode,
30 pub message: String,
31}
32
33impl PayError {
34 pub fn new(code: PayErrorCode, message: impl Into<String>) -> Self {
35 Self {
36 code,
37 message: message.into(),
38 }
39 }
40}
41
42impl From<reqwest::Error> for PayError {
43 fn from(e: reqwest::Error) -> Self {
44 PayError::new(PayErrorCode::HttpTransport, e.to_string())
45 }
46}
47
48impl From<serde_json::Error> for PayError {
49 fn from(e: serde_json::Error) -> Self {
50 PayError::new(PayErrorCode::ProtocolMalformed, format!("json: {e}"))
51 }
52}