routerify_websocket/
error.rs1use derive_more::Display;
2use std::fmt::{self, Debug, Display, Formatter};
3
4type BoxError = Box<dyn std::error::Error + Send + Sync>;
5
6#[derive(Display)]
8#[display(fmt = "routerify-websocket: {}")]
9pub enum WebsocketError {
10 #[display(fmt = "Websocket upgrade error: {}", _0)]
12 Upgrade(BoxError),
13
14 #[display(fmt = "Failed to receive a message from the websocket connection: {}", _0)]
16 MessageReceive(BoxError),
17
18 #[display(fmt = "Failed to check websocket's ready status to send messages: {}", _0)]
20 ReadyStatus(BoxError),
21
22 #[display(fmt = "Failed to send a message to the websocket connection: {}", _0)]
24 MessageSend(BoxError),
25
26 #[display(fmt = "Failed to flush messages to the websocket connection: {}", _0)]
28 MessageFlush(BoxError),
29
30 #[display(fmt = "Failed to decode message data as text: {}", _0)]
32 DecodeText(BoxError),
33
34 #[cfg(feature = "json")]
36 #[display(fmt = "Failed to decode the message data as JSON: {}", _0)]
37 DecodeJson(BoxError),
38
39 #[cfg(feature = "json")]
41 #[display(fmt = "Failed to convert a struct to JSON: {}", _0)]
42 EncodeJson(BoxError),
43
44 #[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 {}