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
use thiserror::Error;

pub(crate) type Result<T, E = ClientError> = std::result::Result<T, E>;

/// WebSocket error type.
#[cfg(any(feature = "ws-async-std", feature = "ws-tokio"))]
pub use async_tungstenite::tungstenite::Error as WsError;

/// The error type for rpc transport.
#[derive(Debug, Error)]
pub enum ClientError {
    /// Json serialization/deserialization error.
    #[error(transparent)]
    Json(#[from] serde_json::Error),

    /// HTTP error.
    #[cfg(feature = "http-async-std")]
    #[error(transparent)]
    Http(#[from] anyhow::Error),

    /// HTTP error.
    #[cfg(feature = "http-tokio")]
    #[error(transparent)]
    Http(#[from] reqwest::Error),

    /// WebSocket protocol error.
    #[cfg(any(feature = "ws-async-std", feature = "ws-tokio"))]
    #[error(transparent)]
    WebSocket(#[from] WsError),
    /// WebSocket request timeout.
    #[cfg(any(feature = "ws-async-std", feature = "ws-tokio"))]
    #[error("WebSocket request timeout")]
    WsRequestTimeout,
    /// Duplicate request ID.
    #[cfg(any(feature = "ws-async-std", feature = "ws-tokio"))]
    #[error("Duplicate request ID")]
    DuplicateRequestId,
    /// Invalid Request ID.
    #[cfg(any(feature = "ws-async-std", feature = "ws-tokio"))]
    #[error("Invalid request ID")]
    InvalidRequestId,
    /// Invalid Subscription ID.
    #[cfg(any(feature = "ws-async-std", feature = "ws-tokio"))]
    #[error("Invalid subscription ID")]
    InvalidSubscriptionId,
    /// Internal channel error
    #[cfg(any(feature = "ws-async-std", feature = "ws-tokio"))]
    #[error("Internal channel error")]
    InternalChannel,
}