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("connection closed")]
36 Closed,
37}
38
39#[cfg(test)]
40mod tests {
41 use super::*;
42
43 #[test]
44 fn display_messages() {
45 assert_eq!(WsError::AuthMissing.to_string(), "authentication token missing");
46 assert_eq!(WsError::AuthInvalid.to_string(), "authentication token invalid");
47 assert_eq!(WsError::TooManyConnections.to_string(), "too many connections");
48 assert_eq!(WsError::BroadcastFull.to_string(), "broadcast channel full");
49 assert_eq!(WsError::InvalidMessage.to_string(), "invalid message");
50 assert_eq!(WsError::Closed.to_string(), "connection closed");
51 }
52
53 #[test]
54 fn clone_eq() {
55 let e = WsError::AuthMissing;
56 assert_eq!(e.clone(), WsError::AuthMissing);
57 assert_ne!(WsError::AuthMissing, WsError::Closed);
58 }
59}