substrate_api_client/rpc/
error.rs1use alloc::{boxed::Box, string::String};
19use core::error::Error as ErrorT;
20
21pub type Result<T> = core::result::Result<T, Error>;
22
23#[derive(Debug)]
24pub enum Error {
25 SerdeJson(serde_json::error::Error),
26 ExtrinsicFailed(String),
27 MpscSend(String),
28 InvalidUrl(String),
29 RecvError(String),
30 Io(String),
31 MaxConnectionAttemptsExceeded,
32 ConnectionClosed,
33 Client(Box<dyn ErrorT + Send + Sync + 'static>),
34}
35
36impl From<serde_json::error::Error> for Error {
37 fn from(error: serde_json::error::Error) -> Self {
38 Self::SerdeJson(error)
39 }
40}
41
42#[cfg(feature = "tungstenite-client")]
43impl From<tungstenite::Error> for Error {
44 fn from(error: tungstenite::Error) -> Self {
45 Self::Client(Box::new(error))
46 }
47}
48
49#[cfg(feature = "std")]
50#[allow(unused_imports)]
51pub use std_only::*;
52#[cfg(feature = "std")]
53mod std_only {
54 use super::*;
55 use std::sync::mpsc::{RecvError, SendError};
56
57 impl From<SendError<String>> for Error {
58 fn from(error: SendError<String>) -> Self {
59 Self::MpscSend(error.0)
60 }
61 }
62
63 impl From<RecvError> for Error {
64 fn from(error: RecvError) -> Self {
65 Self::RecvError(format!("{error:?}"))
66 }
67 }
68
69 impl From<std::io::Error> for Error {
70 fn from(error: std::io::Error) -> Self {
71 Self::Io(format!("{error:?}"))
72 }
73 }
74
75 impl From<url::ParseError> for Error {
76 fn from(error: url::ParseError) -> Self {
77 Self::InvalidUrl(format!("{error:?}"))
78 }
79 }
80}