Skip to main content

oxigdal_ws/
error.rs

1//! Error types for WebSocket operations.
2
3/// Result type for WebSocket operations.
4pub type Result<T> = std::result::Result<T, Error>;
5
6/// Errors that can occur during WebSocket operations.
7#[derive(Debug, thiserror::Error)]
8pub enum Error {
9    /// WebSocket connection error
10    #[error("WebSocket connection error: {0}")]
11    Connection(String),
12
13    /// WebSocket send error
14    #[error("Failed to send WebSocket message: {0}")]
15    Send(String),
16
17    /// WebSocket receive error
18    #[error("Failed to receive WebSocket message: {0}")]
19    Receive(String),
20
21    /// Protocol error
22    #[error("Protocol error: {0}")]
23    Protocol(String),
24
25    /// Serialization error
26    #[error("Serialization error: {0}")]
27    Serialization(String),
28
29    /// Deserialization error
30    #[error("Deserialization error: {0}")]
31    Deserialization(String),
32
33    /// Compression error
34    #[error("Compression error: {0}")]
35    Compression(String),
36
37    /// Decompression error
38    #[error("Decompression error: {0}")]
39    Decompression(String),
40
41    /// Subscription error
42    #[error("Subscription error: {0}")]
43    Subscription(String),
44
45    /// Authentication error
46    #[error("Authentication failed: {0}")]
47    Authentication(String),
48
49    /// Authorization error
50    #[error("Authorization failed: {0}")]
51    Authorization(String),
52
53    /// Rate limit exceeded
54    #[error("Rate limit exceeded: {0}")]
55    RateLimit(String),
56
57    /// Invalid message
58    #[error("Invalid message: {0}")]
59    InvalidMessage(String),
60
61    /// Invalid parameter
62    #[error("Invalid parameter: {0}")]
63    InvalidParameter(String),
64
65    /// Resource not found
66    #[error("Resource not found: {0}")]
67    NotFound(String),
68
69    /// Server error
70    #[error("Server error: {0}")]
71    Server(String),
72
73    /// Client error
74    #[error("Client error: {0}")]
75    Client(String),
76
77    /// Timeout error
78    #[error("Operation timed out: {0}")]
79    Timeout(String),
80
81    /// Channel send error
82    #[error("Channel send error")]
83    ChannelSend,
84
85    /// Channel receive error
86    #[error("Channel receive error")]
87    ChannelReceive,
88
89    /// IO error
90    #[error("IO error: {0}")]
91    Io(#[from] std::io::Error),
92
93    /// OxiGDAL core error
94    #[error("OxiGDAL error: {0}")]
95    Core(String),
96
97    /// JSON error
98    #[error("JSON error: {0}")]
99    Json(#[from] serde_json::Error),
100
101    /// MessagePack error
102    #[error("MessagePack error: {0}")]
103    MessagePack(String),
104
105    /// Axum error
106    #[error("Axum error: {0}")]
107    Axum(String),
108
109    /// Other error
110    #[error("Other error: {0}")]
111    Other(String),
112}
113
114impl From<axum::Error> for Error {
115    fn from(err: axum::Error) -> Self {
116        Error::Axum(err.to_string())
117    }
118}
119
120impl From<rmp_serde::encode::Error> for Error {
121    fn from(err: rmp_serde::encode::Error) -> Self {
122        Error::MessagePack(err.to_string())
123    }
124}
125
126impl From<rmp_serde::decode::Error> for Error {
127    fn from(err: rmp_serde::decode::Error) -> Self {
128        Error::MessagePack(err.to_string())
129    }
130}
131
132impl<T> From<tokio::sync::mpsc::error::SendError<T>> for Error {
133    fn from(_: tokio::sync::mpsc::error::SendError<T>) -> Self {
134        Error::ChannelSend
135    }
136}
137
138impl From<tokio::sync::oneshot::error::RecvError> for Error {
139    fn from(_: tokio::sync::oneshot::error::RecvError) -> Self {
140        Error::ChannelReceive
141    }
142}