1use thiserror::Error;
7
8#[derive(Debug, Error, Clone, PartialEq, Eq)]
13pub enum WsError {
14 #[error("authentication token missing")]
16 AuthMissing,
17
18 #[error("authentication token invalid")]
20 AuthInvalid,
21
22 #[error("too many connections")]
24 TooManyConnections,
25
26 #[error("broadcast channel full")]
28 BroadcastFull,
29
30 #[error("invalid message")]
32 InvalidMessage,
33
34 #[error("malformed compressed payload")]
37 Compression,
38
39 #[error("payload exceeds size limit")]
42 PayloadTooLarge,
43
44 #[error("redis error: {0}")]
48 Redis(String),
49
50 #[error("connection closed")]
52 Closed,
53}
54
55#[allow(
59 clippy::unwrap_used,
60 clippy::expect_used,
61 clippy::indexing_slicing,
62 clippy::panic
63)]
64#[cfg(test)]
65mod tests {
66 use super::*;
67
68 #[test]
69 fn display_messages() {
70 assert_eq!(
71 WsError::AuthMissing.to_string(),
72 "authentication token missing"
73 );
74 assert_eq!(
75 WsError::AuthInvalid.to_string(),
76 "authentication token invalid"
77 );
78 assert_eq!(
79 WsError::TooManyConnections.to_string(),
80 "too many connections"
81 );
82 assert_eq!(WsError::BroadcastFull.to_string(), "broadcast channel full");
83 assert_eq!(WsError::InvalidMessage.to_string(), "invalid message");
84 assert_eq!(
85 WsError::Compression.to_string(),
86 "malformed compressed payload"
87 );
88 assert_eq!(
89 WsError::PayloadTooLarge.to_string(),
90 "payload exceeds size limit"
91 );
92 assert_eq!(
93 WsError::Redis("down".to_string()).to_string(),
94 "redis error: down"
95 );
96 assert_eq!(WsError::Closed.to_string(), "connection closed");
97 }
98
99 #[test]
100 fn clone_eq() {
101 let e = WsError::AuthMissing;
102 assert_eq!(e.clone(), WsError::AuthMissing);
103 assert_ne!(WsError::AuthMissing, WsError::Closed);
104 }
105}