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 = "ws-client")]
43impl From<ws::Error> for Error {
44 fn from(error: ws::Error) -> Self {
45 Self::Client(Box::new(error))
46 }
47}
48
49#[cfg(feature = "tungstenite-client")]
50impl From<tungstenite::Error> for Error {
51 fn from(error: tungstenite::Error) -> Self {
52 Self::Client(Box::new(error))
53 }
54}
55
56#[cfg(feature = "std")]
57#[allow(unused_imports)]
58pub use std_only::*;
59#[cfg(feature = "std")]
60mod std_only {
61 use super::*;
62 use std::sync::mpsc::{RecvError, SendError};
63
64 impl From<SendError<String>> for Error {
65 fn from(error: SendError<String>) -> Self {
66 Self::MpscSend(error.0)
67 }
68 }
69
70 impl From<RecvError> for Error {
71 fn from(error: RecvError) -> Self {
72 Self::RecvError(format!("{error:?}"))
73 }
74 }
75
76 impl From<std::io::Error> for Error {
77 fn from(error: std::io::Error) -> Self {
78 Self::Io(format!("{error:?}"))
79 }
80 }
81
82 impl From<url::ParseError> for Error {
83 fn from(error: url::ParseError) -> Self {
84 Self::InvalidUrl(format!("{error:?}"))
85 }
86 }
87}