Skip to main content

ferro_broadcast/
error.rs

1//! Error types for the broadcast system.
2
3use thiserror::Error;
4
5/// Errors that can occur during broadcasting.
6#[derive(Error, Debug)]
7pub enum Error {
8    /// WebSocket connection error.
9    #[error("websocket error: {0}")]
10    WebSocket(String),
11
12    /// Channel not found.
13    #[error("channel not found: {0}")]
14    ChannelNotFound(String),
15
16    /// Authorization failed.
17    #[error("authorization failed: {0}")]
18    AuthorizationFailed(String),
19
20    /// Client not connected.
21    #[error("client not connected: {0}")]
22    ClientNotConnected(String),
23
24    /// Serialization error.
25    #[error("serialization error: {0}")]
26    Serialization(#[from] serde_json::Error),
27
28    /// Channel is full (too many subscribers).
29    #[error("channel is full")]
30    ChannelFull,
31
32    /// Generic error.
33    #[error("{0}")]
34    Other(String),
35}
36
37impl Error {
38    /// Create a WebSocket error.
39    pub fn websocket(msg: impl Into<String>) -> Self {
40        Self::WebSocket(msg.into())
41    }
42
43    /// Create an authorization failed error.
44    pub fn unauthorized(msg: impl Into<String>) -> Self {
45        Self::AuthorizationFailed(msg.into())
46    }
47}