use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("WebSocket transport error: {0}")]
Transport(Box<tokio_tungstenite::tungstenite::Error>),
#[error("connection closed before {context}")]
ConnectionClosed { context: &'static str },
#[error("invalid URL: {0}")]
InvalidUrl(#[from] url::ParseError),
#[error("malformed protocol message: {0}")]
Protocol(String),
#[error("JSON serialization failed: {0}")]
Json(Box<serde_json::Error>),
#[error("retry budget exhausted ({attempts} attempts) — last error: {last_error}")]
RetriesExhausted { attempts: u32, last_error: String },
#[error("bot decision error (safe_mode off): {0}")]
BotDecision(String),
#[error("untrusted gateway URL: {0}")]
UntrustedGateway(String),
}
impl From<tokio_tungstenite::tungstenite::Error> for Error {
fn from(err: tokio_tungstenite::tungstenite::Error) -> Self {
Error::Transport(Box::new(err))
}
}
impl From<serde_json::Error> for Error {
fn from(err: serde_json::Error) -> Self {
Error::Json(Box::new(err))
}
}