use std::fmt;
#[derive(Debug)]
pub enum StreamError {
WebSocket(tungstenite::Error),
Json(serde_json::Error),
AuthFailed(String),
ConnectionClosed,
}
impl fmt::Display for StreamError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
StreamError::WebSocket(e) => write!(f, "WebSocket error: {}", e),
StreamError::Json(e) => write!(f, "JSON error: {}", e),
StreamError::AuthFailed(msg) => write!(f, "Authentication failed: {}", msg),
StreamError::ConnectionClosed => write!(f, "Connection closed"),
}
}
}
impl std::error::Error for StreamError {}
impl From<tungstenite::Error> for StreamError {
fn from(e: tungstenite::Error) -> Self {
StreamError::WebSocket(e)
}
}
impl From<serde_json::Error> for StreamError {
fn from(e: serde_json::Error) -> Self {
StreamError::Json(e)
}
}