1use crate::data::common::LinkDescription;
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5use std::error::Error;
6use std::fmt;
7
8#[derive(Debug, Serialize, Deserialize)]
10pub struct PaypalError {
11 pub name: String,
13 pub message: Option<String>,
15 pub debug_id: Option<String>,
17 pub details: Vec<HashMap<String, String>>,
19 pub error: Option<String>,
21 pub error_description: Option<String>,
23 pub links: Vec<LinkDescription>,
25}
26
27impl fmt::Display for PaypalError {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 write!(f, "{:#?}", self)
30 }
31}
32
33impl Error for PaypalError {}
34
35#[derive(Debug)]
37pub enum ResponseError {
38 ApiError(PaypalError),
40 HttpError(reqwest::Error),
42}
43
44impl fmt::Display for ResponseError {
45 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46 match self {
47 ResponseError::ApiError(e) => write!(f, "{}", e),
48 ResponseError::HttpError(e) => write!(f, "{}", e),
49 }
50 }
51}
52
53impl Error for ResponseError {
54 fn source(&self) -> Option<&(dyn Error + 'static)> {
55 match self {
56 ResponseError::ApiError(e) => Some(e),
57 ResponseError::HttpError(e) => Some(e),
58 }
59 }
60}
61
62impl From<PaypalError> for ResponseError {
64 fn from(e: PaypalError) -> Self {
65 ResponseError::ApiError(e)
66 }
67}
68
69impl From<reqwest::Error> for ResponseError {
71 fn from(e: reqwest::Error) -> Self {
72 ResponseError::HttpError(e)
73 }
74}
75
76#[derive(Debug)]
78pub struct InvalidCurrencyError(pub String);
79
80impl fmt::Display for InvalidCurrencyError {
81 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
82 write!(f, "{:?} is not a valid currency", self.0)
83 }
84}
85
86impl Error for InvalidCurrencyError {}
87
88#[derive(Debug)]
90pub struct InvalidCountryError(pub String);
91
92impl fmt::Display for InvalidCountryError {
93 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
94 write!(f, "{:?} is not a valid country", self.0)
95 }
96}
97
98impl Error for InvalidCountryError {}