polymesh_api_client/
error.rs1#[cfg(feature = "std")]
2use thiserror::Error;
3
4#[cfg(not(feature = "std"))]
5use alloc::{fmt, format, string::String};
6
7#[derive(Debug)]
8#[cfg_attr(feature = "std", derive(Error))]
9pub enum Error {
10 #[cfg_attr(feature = "std", error("Std io error: {0}"))]
11 #[cfg(feature = "std")]
12 StdIo(std::io::Error),
13
14 #[cfg_attr(feature = "std", error("Json error: {0}"))]
15 Json(serde_json::Error),
16
17 #[cfg_attr(feature = "std", error("hex error: {0}"))]
18 Hex(hex::FromHexError),
19
20 #[cfg_attr(feature = "std", error("http error: {0}"))]
21 Http(http::Error),
22
23 #[cfg_attr(feature = "std", error("http uri error: {0}"))]
24 HttpUri(http::uri::InvalidUri),
25
26 #[cfg_attr(feature = "std", error("parity-scale-codec error: {0}"))]
27 ParityScaleCodec(codec::Error),
28
29 #[cfg_attr(feature = "std", error("sp-core crypto secret error: {0}"))]
30 SecretStringError(String),
31
32 #[cfg_attr(feature = "std", error("sp-core crypto error: {0}"))]
33 CoreCryptoError(String),
34
35 #[cfg_attr(
36 feature = "std",
37 error("Call API incompatible with connected chain: {0}")
38 )]
39 IncompatibleCall(String),
40
41 #[cfg_attr(feature = "std", error("Schema failed to parse: {0}"))]
42 SchemaParseFailed(String),
43
44 #[cfg_attr(feature = "std", error("Metadata failed to parse: {0}"))]
45 MetadataParseFailed(String),
46
47 #[cfg_attr(feature = "std", error("ExtrinsicError: {0}"))]
48 ExtrinsicError(String),
49
50 #[cfg_attr(feature = "std", error("RpcClient: {0}"))]
51 RpcClient(String),
52
53 #[cfg_attr(feature = "std", error("Decode type failed: {0}"))]
54 DecodeTypeFailed(String),
55
56 #[cfg_attr(feature = "std", error("Encode type failed: {0}"))]
57 EncodeTypeFailed(String),
58
59 #[cfg_attr(feature = "std", error("Signing transaction failed: {0}"))]
60 SigningTransactionFailed(String),
61
62 #[cfg_attr(feature = "std", error("Jsonrpsee error: {0}"))]
63 Jsonrpsee(jsonrpsee::core::Error),
64
65 #[cfg_attr(
66 feature = "std",
67 error("The signer's account {0} doesn't match the transaction's account: {1}")
68 )]
69 WrongSignerAccount(String, String),
70}
71
72#[cfg(feature = "std")]
73impl From<std::io::Error> for Error {
74 fn from(e: std::io::Error) -> Self {
75 Self::StdIo(e)
76 }
77}
78
79impl From<serde_json::Error> for Error {
80 fn from(e: serde_json::Error) -> Self {
81 Self::Json(e)
82 }
83}
84
85impl From<hex::FromHexError> for Error {
86 fn from(e: hex::FromHexError) -> Self {
87 Self::Hex(e)
88 }
89}
90
91impl From<http::Error> for Error {
92 fn from(e: http::Error) -> Self {
93 Self::Http(e)
94 }
95}
96
97impl From<http::uri::InvalidUri> for Error {
98 fn from(e: http::uri::InvalidUri) -> Self {
99 Self::HttpUri(e)
100 }
101}
102
103impl From<codec::Error> for Error {
104 fn from(e: codec::Error) -> Self {
105 Self::ParityScaleCodec(e)
106 }
107}
108
109impl From<jsonrpsee::core::Error> for Error {
110 fn from(e: jsonrpsee::core::Error) -> Self {
111 Self::Jsonrpsee(e)
112 }
113}
114
115impl From<sp_core::crypto::SecretStringError> for Error {
116 fn from(e: sp_core::crypto::SecretStringError) -> Self {
117 Self::SecretStringError(format!("{e:?}"))
118 }
119}
120
121impl From<sp_core::crypto::PublicError> for Error {
122 fn from(e: sp_core::crypto::PublicError) -> Self {
123 Self::CoreCryptoError(format!("{e:?}"))
124 }
125}
126
127impl From<subxt_signer::sr25519::Error> for Error {
128 fn from(e: subxt_signer::sr25519::Error) -> Self {
129 Self::SecretStringError(format!("{e:?}"))
130 }
131}
132
133impl From<subxt_signer::ecdsa::Error> for Error {
134 fn from(e: subxt_signer::ecdsa::Error) -> Self {
135 Self::SecretStringError(format!("{e:?}"))
136 }
137}
138
139impl From<subxt_signer::SecretUriError> for Error {
140 fn from(e: subxt_signer::SecretUriError) -> Self {
141 Self::SecretStringError(format!("{e:?}"))
142 }
143}
144
145#[cfg(not(feature = "std"))]
146impl fmt::Display for Error {
147 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
148 write!(f, "{:?}", self)
149 }
150}
151
152pub type Result<T, E = Error> = core::result::Result<T, E>;