routerify_websocket/
error.rs

1use derive_more::Display;
2use std::fmt::{self, Debug, Display, Formatter};
3
4type BoxError = Box<dyn std::error::Error + Send + Sync>;
5
6/// A set of errors that can occur during handling the websocket connections and in other operations.
7#[derive(Display)]
8#[display(fmt = "routerify-websocket: {}")]
9pub enum WebsocketError {
10    /// Websocket upgrade error.
11    #[display(fmt = "Websocket upgrade error: {}", _0)]
12    Upgrade(BoxError),
13
14    /// Failed to receive a message from the websocket connection.
15    #[display(fmt = "Failed to receive a message from the websocket connection: {}", _0)]
16    MessageReceive(BoxError),
17
18    /// Failed to check websocket's ready status to send messages.
19    #[display(fmt = "Failed to check websocket's ready status to send messages: {}", _0)]
20    ReadyStatus(BoxError),
21
22    /// Failed to send a message to the websocket connection.
23    #[display(fmt = "Failed to send a message to the websocket connection: {}", _0)]
24    MessageSend(BoxError),
25
26    /// Failed to flush messages to the websocket connection.
27    #[display(fmt = "Failed to flush messages to the websocket connection: {}", _0)]
28    MessageFlush(BoxError),
29
30    /// Failed to decode message data as text.
31    #[display(fmt = "Failed to decode message data as text: {}", _0)]
32    DecodeText(BoxError),
33
34    /// Failed to decode the message data as `JSON` in [`message.decode_json()`](./struct.Message.html#method.decode_json) method.
35    #[cfg(feature = "json")]
36    #[display(fmt = "Failed to decode the message data as JSON: {}", _0)]
37    DecodeJson(BoxError),
38
39    /// Failed to convert a struct to `JSON` in [`message.json()`](./struct.Message.html#method.json) method.
40    #[cfg(feature = "json")]
41    #[display(fmt = "Failed to convert a struct to JSON: {}", _0)]
42    EncodeJson(BoxError),
43
44    /// Failed to close the websocket connection.
45    #[display(fmt = "Failed to close the websocket connection: {}", _0)]
46    WebSocketClose(BoxError),
47
48    #[doc(hidden)]
49    __Nonexhaustive,
50}
51
52impl Debug for WebsocketError {
53    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
54        Display::fmt(self, f)
55    }
56}
57
58impl std::error::Error for WebsocketError {}
59
60impl PartialEq for WebsocketError {
61    fn eq(&self, other: &Self) -> bool {
62        self.to_string().eq(&other.to_string())
63    }
64}
65
66impl Eq for WebsocketError {}