use thiserror::Error;
#[derive(Debug, Error, Clone, PartialEq, Eq)]
pub enum WsError {
#[error("authentication token missing")]
AuthMissing,
#[error("authentication token invalid")]
AuthInvalid,
#[error("too many connections")]
TooManyConnections,
#[error("broadcast channel full")]
BroadcastFull,
#[error("invalid message")]
InvalidMessage,
#[error("connection closed")]
Closed,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn display_messages() {
assert_eq!(WsError::AuthMissing.to_string(), "authentication token missing");
assert_eq!(WsError::AuthInvalid.to_string(), "authentication token invalid");
assert_eq!(WsError::TooManyConnections.to_string(), "too many connections");
assert_eq!(WsError::BroadcastFull.to_string(), "broadcast channel full");
assert_eq!(WsError::InvalidMessage.to_string(), "invalid message");
assert_eq!(WsError::Closed.to_string(), "connection closed");
}
#[test]
fn clone_eq() {
let e = WsError::AuthMissing;
assert_eq!(e.clone(), WsError::AuthMissing);
assert_ne!(WsError::AuthMissing, WsError::Closed);
}
}