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!(
46 WsError::AuthMissing.to_string(),
47 "authentication token missing"
48 );
49 assert_eq!(
50 WsError::AuthInvalid.to_string(),
51 "authentication token invalid"
52 );
53 assert_eq!(
54 WsError::TooManyConnections.to_string(),
55 "too many connections"
56 );
57 assert_eq!(WsError::BroadcastFull.to_string(), "broadcast channel full");
58 assert_eq!(WsError::InvalidMessage.to_string(), "invalid message");
59 assert_eq!(WsError::Closed.to_string(), "connection closed");
60 }
61
62 #[test]
63 fn clone_eq() {
64 let e = WsError::AuthMissing;
65 assert_eq!(e.clone(), WsError::AuthMissing);
66 assert_ne!(WsError::AuthMissing, WsError::Closed);
67 }
68}