btcpay_client/apis/
mod.rs

1use std::error;
2use std::fmt;
3
4#[derive(Debug, Clone)]
5pub struct ResponseContent<T> {
6    pub status: reqwest::StatusCode,
7    pub content: String,
8    pub entity: Option<T>,
9}
10
11#[derive(Debug)]
12pub enum Error<T> {
13    Reqwest(reqwest::Error),
14    Serde(serde_json::Error),
15    Io(std::io::Error),
16    ResponseError(ResponseContent<T>),
17}
18
19impl <T> fmt::Display for Error<T> {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        let (module, e) = match self {
22            Error::Reqwest(e) => ("reqwest", e.to_string()),
23            Error::Serde(e) => ("serde", e.to_string()),
24            Error::Io(e) => ("IO", e.to_string()),
25            Error::ResponseError(e) => ("response", format!("status code {}", e.status)),
26        };
27        write!(f, "error in {}: {}", module, e)
28    }
29}
30
31impl <T: fmt::Debug> error::Error for Error<T> {
32    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
33        Some(match self {
34            Error::Reqwest(e) => e,
35            Error::Serde(e) => e,
36            Error::Io(e) => e,
37            Error::ResponseError(_) => return None,
38        })
39    }
40}
41
42impl <T> From<reqwest::Error> for Error<T> {
43    fn from(e: reqwest::Error) -> Self {
44        Error::Reqwest(e)
45    }
46}
47
48impl <T> From<serde_json::Error> for Error<T> {
49    fn from(e: serde_json::Error) -> Self {
50        Error::Serde(e)
51    }
52}
53
54impl <T> From<std::io::Error> for Error<T> {
55    fn from(e: std::io::Error) -> Self {
56        Error::Io(e)
57    }
58}
59
60pub fn urlencode<T: AsRef<str>>(s: T) -> String {
61    ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect()
62}
63
64pub mod api_keys_api;
65pub mod apps_api;
66pub mod authorization_api;
67pub mod custodians_api;
68pub mod health_api;
69pub mod invoices_api;
70pub mod lightning_internal_node_api;
71pub mod lightning_store_api;
72pub mod miscelleneous_api;
73pub mod notifications_current_user_api;
74pub mod payment_requests_api;
75pub mod payout_processors_api;
76pub mod pull_payments_management_api;
77pub mod pull_payments_payout_public_api;
78pub mod pull_payments_public_api;
79pub mod server_info_api;
80pub mod store_payment_methods_api;
81pub mod store_payment_methods_lnurl_pay_api;
82pub mod store_payment_methods_lightning_network_api;
83pub mod store_payment_methods_on_chain_api;
84pub mod store_wallet_on_chain_api;
85pub mod stores_api;
86pub mod stores_email_api;
87pub mod stores_payout_processors_api;
88pub mod stores_payouts_api;
89pub mod stores_users_api;
90pub mod users_api;
91pub mod webhooks_api;
92
93pub mod configuration;