rusty_common/websocket/
error.rs1use thiserror::Error;
6use yawc::WebSocketError as YawcError;
7
8pub type WebSocketResult<T> = Result<T, WebSocketError>;
10
11#[derive(Error, Debug)]
13pub enum WebSocketError {
14 #[error("Failed to connect to WebSocket: {0}")]
16 ConnectionError(String),
17
18 #[error("WebSocket authentication failed: {0}")]
20 AuthenticationError(String),
21
22 #[error("WebSocket subscription failed: {0}")]
24 SubscriptionError(String),
25
26 #[error("Failed to process WebSocket message: {0}")]
28 MessageProcessingError(String),
29
30 #[error("Protocol error: {0}")]
32 ProtocolError(String),
33
34 #[error("WebSocket connection closed: {0}")]
36 ConnectionClosed(String),
37
38 #[error("WebSocket operation timed out after {0} milliseconds")]
40 Timeout(u64),
41
42 #[error("WebSocket rate limit exceeded: {0}")]
44 RateLimitExceeded(String),
45
46 #[error("Reconnection failed after {attempts} attempts")]
48 ReconnectionFailed {
49 attempts: u32,
51 },
52
53 #[error("WebSocket is not connected")]
55 NotConnected,
56
57 #[error("Channel error: {0}")]
59 ChannelError(String),
60
61 #[error("I/O error: {0}")]
63 IoError(#[from] std::io::Error),
64
65 #[error("Invalid URL: {0}")]
67 InvalidUrl(#[from] url::ParseError),
68
69 #[error("WebSocket error: {0}")]
71 YawcError(#[from] YawcError),
72
73 #[error("JSON error: {0}")]
75 JsonError(#[from] simd_json::Error),
76
77 #[error("{0}")]
79 Other(String),
80}
81
82impl From<String> for WebSocketError {
83 fn from(s: String) -> Self {
84 WebSocketError::Other(s)
85 }
86}
87
88impl From<&str> for WebSocketError {
89 fn from(s: &str) -> Self {
90 WebSocketError::Other(s.to_string())
91 }
92}