-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathexceptions.rs
More file actions
82 lines (76 loc) · 3.45 KB
/
Copy pathexceptions.rs
File metadata and controls
82 lines (76 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use thiserror_no_std::Error;
#[cfg(any(feature = "json-rpc", feature = "websocket"))]
use super::clients::exceptions::XRPLClientException;
#[cfg(feature = "helpers")]
use super::{
transaction::exceptions::{XRPLSubmitAndWaitException, XRPLTransactionHelperException},
wallet::exceptions::XRPLFaucetException,
};
#[cfg(feature = "wallet")]
use crate::wallet::exceptions::XRPLWalletException;
// Available whenever `signing` is compiled (which requires core+models+wallet),
// or whenever `helpers` is on — the former is a subset of the latter.
#[cfg(all(feature = "core", feature = "models", feature = "wallet"))]
use crate::{
core::exceptions::XRPLCoreException,
models::transactions::exceptions::XRPLTransactionFieldException,
signing::exceptions::{XRPLMultisignException, XRPLSignTransactionException},
utils::exceptions::XRPLUtilsException,
};
use crate::{models::XRPLModelException, XRPLSerdeJsonError};
pub type XRPLHelperResult<T, E = XRPLHelperException> = core::result::Result<T, E>;
#[derive(Debug, Error)]
pub enum XRPLHelperException {
#[cfg(feature = "wallet")]
#[error("XRPL Wallet error: {0}")]
XRPLWalletError(#[from] XRPLWalletException),
#[cfg(feature = "helpers")]
#[error("XRPL Faucet error: {0}")]
XRPLFaucetError(#[from] XRPLFaucetException),
#[cfg(feature = "helpers")]
#[error("XRPL Transaction Helper error: {0}")]
XRPLTransactionHelperError(#[from] XRPLTransactionHelperException),
#[error("XRPL Model error: {0}")]
XRPLModelError(#[from] XRPLModelException),
#[cfg(all(feature = "core", feature = "models", feature = "wallet"))]
#[error("XRPL Core error: {0}")]
XRPLCoreError(#[from] XRPLCoreException),
#[cfg(all(feature = "core", feature = "models", feature = "wallet"))]
#[error("XRPL Transaction Field error: {0}")]
XRPLTransactionFieldError(#[from] XRPLTransactionFieldException),
#[cfg(all(feature = "core", feature = "models", feature = "wallet"))]
#[error("XRPL Utils error: {0}")]
XRPLUtilsError(#[from] XRPLUtilsException),
#[cfg(all(feature = "core", feature = "models", feature = "wallet"))]
#[error("XRPL MultiSign error: {0}")]
XRPLMultiSignError(#[from] XRPLMultisignException),
#[cfg(all(feature = "core", feature = "models", feature = "wallet"))]
#[error("XRPL Sign Transaction error: {0}")]
XRPLSignTransactionError(#[from] XRPLSignTransactionException),
#[cfg(any(feature = "json-rpc", feature = "websocket"))]
#[error("XRPL Client error: {0}")]
XRPLClientError(#[from] XRPLClientException),
#[error("serde_json error: {0}")]
XRPLSerdeJsonError(#[from] XRPLSerdeJsonError),
#[error("From hex error: {0}")]
FromHexError(#[from] hex::FromHexError),
#[cfg(feature = "std")]
#[error("URL parse error: {0}")]
UrlParseError(#[from] url::ParseError),
}
impl From<serde_json::Error> for XRPLHelperException {
fn from(error: serde_json::Error) -> Self {
XRPLHelperException::XRPLSerdeJsonError(XRPLSerdeJsonError::SerdeJsonError(error))
}
}
// `XRPLSignTransactionException` is now a direct variant of
// `XRPLHelperException` (see `XRPLSignTransactionError`), so the `From` impl
// is derived automatically.
#[cfg(feature = "helpers")]
impl From<XRPLSubmitAndWaitException> for XRPLHelperException {
fn from(error: XRPLSubmitAndWaitException) -> Self {
XRPLHelperException::XRPLTransactionHelperError(
XRPLTransactionHelperException::XRPLSubmitAndWaitError(error),
)
}
}