1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
//!
//! [`enum@Error`] enum declaration for server-side WebSocket errors.
//!
use thiserror::Error;
use tokio::sync::mpsc::error::SendError;
/// Errors produced by the [`WebSocketServer`](super::WebSocketServer).
#[derive(Debug, Error)]
pub enum Error {
#[error("{0}")]
Other(String),
#[error("{0}")]
Listen(String),
/// Indicates that no messages have been received
/// within the specified timeout period
#[error("Connection timeout")]
ConnectionTimeout,
/// Indicates that the data received is not a
/// valid handshake message
#[error("Malformed handshake message")]
MalformedHandshake,
/// Indicates that the data received is not a
/// valid or acceptable message
#[error("Malformed handshake message")]
MalformedMessage,
/// Indicates handler negotiation failure
/// This error code is reserved for structs
/// implementing WebSocket handler.
#[error("Negotiation failure")]
NegotiationFailure,
/// Indicates handler negotiation failure
/// with a specific reason
/// This error code is reserved for structs
/// implementing WebSocket handler.
#[error("Negotiation failure: {0}")]
NegotiationFailureWithReason(String),
/// Error sending response via the
/// tokio MPSC response channel
#[error("Response channel send error {0:?}")]
ResponseChannelError(#[from] SendError<tungstenite::Message>),
/// WebSocket error produced by the underlying
/// Tungstenite WebSocket crate
#[error("WebSocket error: {0}")]
WebSocketError(#[from] tungstenite::Error),
/// Connection terminated abnormally
#[error("Connection closed abnormally")]
AbnormalClose,
/// Server closed connection
#[error("Server closed connection")]
ServerClose,
#[error("Error signaling listener shutdown: {0}")]
Stop(String),
#[error("Error signaling listener shutdown: {0}")]
Done(String),
#[error("Error waiting for listener shutdown: {0}")]
Join(String),
#[error(transparent)]
IoError(#[from] std::io::Error),
}
impl From<String> for Error {
fn from(value: String) -> Self {
Error::Other(value)
}
}