use crate::data::common::LinkDescription;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::error::Error;
use std::fmt;
#[derive(Debug, Serialize, Deserialize)]
pub struct PaypalError {
pub name: String,
pub message: Option<String>,
pub debug_id: Option<String>,
pub details: Vec<HashMap<String, String>>,
pub error: Option<String>,
pub error_description: Option<String>,
pub links: Vec<LinkDescription>,
}
impl fmt::Display for PaypalError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:#?}", self)
}
}
impl Error for PaypalError {}
#[derive(Debug)]
pub enum ResponseError {
ApiError(PaypalError),
HttpError(reqwest::Error),
}
impl fmt::Display for ResponseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ResponseError::ApiError(e) => write!(f, "{}", e),
ResponseError::HttpError(e) => write!(f, "{}", e),
}
}
}
impl Error for ResponseError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
ResponseError::ApiError(e) => Some(e),
ResponseError::HttpError(e) => Some(e),
}
}
}
impl From<PaypalError> for ResponseError {
fn from(e: PaypalError) -> Self {
ResponseError::ApiError(e)
}
}
impl From<reqwest::Error> for ResponseError {
fn from(e: reqwest::Error) -> Self {
ResponseError::HttpError(e)
}
}
#[derive(Debug)]
pub struct InvalidCurrencyError(pub String);
impl fmt::Display for InvalidCurrencyError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?} is not a valid currency", self.0)
}
}
impl Error for InvalidCurrencyError {}
#[derive(Debug)]
pub struct InvalidCountryError(pub String);
impl fmt::Display for InvalidCountryError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?} is not a valid country", self.0)
}
}
impl Error for InvalidCountryError {}