Skip to main content

sms_client/ws/
error.rs

1//! WebSocket-related error types.
2
3/// Errors that can occur with WebSocket operations.
4#[derive(thiserror::Error, Debug)]
5pub enum WebsocketError {
6    /// Invalid configured websocket connection URL, failed to create request
7    #[error("Invalid WebSocket request URL configured")]
8    InvalidRequest,
9
10    /// WebSocket connection error
11    #[error("WebSocket connection failed: {0}")]
12    ConnectionError(#[from] tokio_tungstenite::tungstenite::Error),
13
14    /// Url parse or generation error
15    #[error("Invalid WebSocket URL: {0}")]
16    UrlError(#[from] UrlError),
17
18    /// HTTP error when establishing WebSocket connection
19    #[error("HTTP error: {0}")]
20    HttpError(#[from] http::Error),
21
22    /// HTTP authorization header value failure
23    #[error("Invalid WebSocket header value: {0}")]
24    InvalidHeader(#[from] http::header::InvalidHeaderValue),
25
26    /// JSON serialization/deserialization error
27    #[error("JSON error: {0}")]
28    JsonError(#[from] serde_json::Error),
29
30    /// TLS configuration error
31    #[error("TLS error: {0}")]
32    TLSError(String),
33
34    /// Http Unauthorized (401), token is missing or invalid
35    #[error("The WebSocket connection was unauthorized")]
36    Unauthorized,
37
38    /// Already connected
39    #[error("WebSocket is already connected")]
40    AlreadyConnected,
41
42    /// Not connected
43    #[error("WebSocket is not connected")]
44    NotConnected,
45
46    /// Failed to send message
47    #[error("Failed to send message to WebSocket")]
48    SendError,
49
50    /// Channel communication error
51    #[error("Internal channel communication error")]
52    ChannelError,
53
54    /// Timeout error
55    #[error("Operation timed out")]
56    Timeout,
57}
58
59/// An error generated from URL parsing or generation.
60#[derive(thiserror::Error, Debug)]
61pub enum UrlError {
62    /// Invalid Uri provided for websocket connection
63    #[error(transparent)]
64    Http(#[from] http::uri::InvalidUri),
65
66    /// Failed to parse connection URL to add event filters
67    #[error(transparent)]
68    Url(#[from] url::ParseError),
69}
70
71/// Result type alias for WebSocket operations.
72pub type WebsocketResult<T> = Result<T, WebsocketError>;