//! WebSocket transport errors.

use thiserror::Error;

/// WebSocket transport errors.
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum WebSocketError {
    /// Connection failed
    #[error("Connection failed: {0}")]
    ConnectionFailed(String),

    /// Connection closed
    #[error("Connection closed: code={code}, reason={reason}")]
    ConnectionClosed {
        /// WebSocket close code
        code: u16,
        /// Close reason
        reason: String,
    },

    /// Message parsing error
    #[error("Message parse error: {0}")]
    MessageParseError(String),

    /// Receive timeout
    #[error("Receive timeout")]
    ReceiveTimeout,

    /// Reconnection exhausted
    #[error("Reconnection exhausted ({attempts} attempts)")]
    ReconnectionExhausted {
        /// Number of attempts made
        attempts: u32,
    },
}
