use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Debug)]
pub enum Error {
#[error("WebSocket error: {0}")]
WebSocket(String),
#[error("Connection error: {0}")]
Connection(String),
#[error("Protocol error: {0}")]
Protocol(String),
#[error("Serialization error: {0}")]
Serialization(String),
#[error("Compression error: {0}")]
Compression(String),
#[error("Broadcast error: {0}")]
Broadcast(String),
#[error("Room error: {0}")]
Room(String),
#[error("Subscription error: {0}")]
Subscription(String),
#[error("Channel error: {0}")]
Channel(String),
#[error("Timeout error: {0}")]
Timeout(String),
#[error("Invalid message: {0}")]
InvalidMessage(String),
#[error("Invalid state: {0}")]
InvalidState(String),
#[error("Resource exhausted: {0}")]
ResourceExhausted(String),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("MessagePack error: {0}")]
MessagePack(String),
#[error("OxiGDAL core error: {0}")]
Core(#[from] oxigdal_core::error::OxiGdalError),
}
impl From<tokio_tungstenite::tungstenite::Error> for Error {
fn from(err: tokio_tungstenite::tungstenite::Error) -> Self {
Error::WebSocket(err.to_string())
}
}
impl<T> From<tokio::sync::mpsc::error::SendError<T>> for Error {
fn from(err: tokio::sync::mpsc::error::SendError<T>) -> Self {
Error::Channel(err.to_string())
}
}
impl From<rmp_serde::encode::Error> for Error {
fn from(err: rmp_serde::encode::Error) -> Self {
Error::MessagePack(err.to_string())
}
}
impl From<rmp_serde::decode::Error> for Error {
fn from(err: rmp_serde::decode::Error) -> Self {
Error::MessagePack(err.to_string())
}
}