use thiserror::Error;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PayErrorCode {
HttpTransport,
HttpStatus,
ProtocolMalformed,
ProtocolUnknown,
WalletNotFound,
SigningFailed,
UnsupportedChain,
DiscoveryFailed,
InvalidInput,
}
#[derive(Debug, Error)]
#[error("[{code:?}] {message}")]
pub struct PayError {
pub code: PayErrorCode,
pub message: String,
}
impl PayError {
pub fn new(code: PayErrorCode, message: impl Into<String>) -> Self {
Self {
code,
message: message.into(),
}
}
}
impl From<reqwest::Error> for PayError {
fn from(e: reqwest::Error) -> Self {
PayError::new(PayErrorCode::HttpTransport, e.to_string())
}
}
impl From<serde_json::Error> for PayError {
fn from(e: serde_json::Error) -> Self {
PayError::new(PayErrorCode::ProtocolMalformed, format!("json: {e}"))
}
}