polymarket_client_sdk/rtds/
error.rs1#![expect(
2 clippy::module_name_repetitions,
3 reason = "Error types include the module name to indicate their scope"
4)]
5
6use std::error::Error as StdError;
7use std::fmt;
8
9#[non_exhaustive]
11#[derive(Debug)]
12pub enum RtdsError {
13 Connection(tokio_tungstenite::tungstenite::Error),
15 MessageParse(serde_json::Error),
17 SubscriptionFailed(String),
19 AuthenticationFailed,
21 ConnectionClosed,
23 Timeout,
25 InvalidMessage(String),
27}
28
29impl fmt::Display for RtdsError {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 match self {
32 Self::Connection(err) => write!(f, "RTDS WebSocket connection error: {err}"),
33 Self::MessageParse(err) => write!(f, "Failed to parse RTDS message: {err}"),
34 Self::SubscriptionFailed(reason) => write!(f, "RTDS subscription failed: {reason}"),
35 Self::AuthenticationFailed => write!(f, "RTDS WebSocket authentication failed"),
36 Self::ConnectionClosed => write!(f, "RTDS WebSocket connection closed"),
37 Self::Timeout => write!(f, "RTDS WebSocket operation timed out"),
38 Self::InvalidMessage(msg) => write!(f, "Invalid RTDS message: {msg}"),
39 }
40 }
41}
42
43impl StdError for RtdsError {
44 fn source(&self) -> Option<&(dyn StdError + 'static)> {
45 match self {
46 Self::Connection(err) => Some(err),
47 Self::MessageParse(err) => Some(err),
48 _ => None,
49 }
50 }
51}
52
53impl From<RtdsError> for crate::error::Error {
55 fn from(err: RtdsError) -> Self {
56 crate::error::Error::with_source(crate::error::Kind::WebSocket, err)
57 }
58}