use thiserror::Error;
#[derive(Debug, Error)]
pub enum ProtocolError {
#[error("failed to serialize message: {0}")]
Serialization(serde_json::Error),
#[error("failed to decode message: {0}")]
Deserialization(serde_json::Error),
#[error("missing or empty message type")]
MissingType,
#[error("unknown message type: {0}")]
UnknownType(String),
#[error("failed to deserialize payload for message type '{type_}': {source}")]
InvalidPayload {
type_: String,
source: serde_json::Error,
},
#[error("invalid session ID in message: {source}")]
InvalidSession {
source: serde_json::Error,
},
#[error("invalid channel in message")]
InvalidChannel,
#[error("missing session ID in message")]
MissingSession,
#[error("connection closed unexpectedly")]
ConnectionClosed,
#[error("authentication failed: {reason}")]
AuthFailed {
reason: String,
},
#[error("session not found: {session_id}")]
SessionNotFound {
session_id: String,
},
#[error("session is full, maximum frontend connections reached")]
SessionFull,
#[error("internal error: {0}")]
Internal(String),
}
pub type ProtocolResult<T> = Result<T, ProtocolError>;