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("malformed compressed payload")]
Compression,
#[error("payload exceeds size limit")]
PayloadTooLarge,
#[error("redis error: {0}")]
Redis(String),
#[error("connection closed")]
Closed,
}
#[allow(
clippy::unwrap_used,
clippy::expect_used,
clippy::indexing_slicing,
clippy::panic
)]
#[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::Compression.to_string(),
"malformed compressed payload"
);
assert_eq!(
WsError::PayloadTooLarge.to_string(),
"payload exceeds size limit"
);
assert_eq!(
WsError::Redis("down".to_string()).to_string(),
"redis error: down"
);
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);
}
}