//! cross-ws error module.

use thiserror::Error;

/// Specific error to each backend.
pub type BackendError = crate::websocket::backend::BackendError;

/// All possible errors emitted by the WebSocket.
#[derive(Debug, Error)]
pub enum Error {
    /// Error emitted if the connection fails.
    #[error("Connection error: {0:?}")]
    ConnectionError(BackendError),
    /// Error emitted if sending a message fails.
    #[error("Send error: {0:?}")]
    SendError(BackendError),
    /// Error emitted if receiving a message fails.
    #[error("Receive error: {0:?}")]
    ReceiveError(BackendError),
    /// Error emitted if a mutex lock fails.
    #[error("Mutex lock error: {0}")]
    LockError(String),
    /// Error emitted if WebSocket creation fails.
    #[error("WebSocket creation failed")]
    WebSocketCreationFailed,
    /// Error emitted if a type cast fails.
    #[error("Type cast failed: {0}")]
    CastError(String),
    /// Error emitted if an unsupported message type is encountered.
    #[error("Unsupported message type: {0}")]
    UnsupportedMessageType(String),
}

/// Result type of cross-ws.
pub type Result<T> = std::result::Result<T, Error>;
