use std::fmt::Display;
use crate::spot::sbe::error::SbeDecodeError;
#[derive(Debug)]
pub enum BinanceWsApiError {
ClientError(String),
HandlerUnavailable(String),
ConnectionError(String),
AuthenticationError(String),
RequestRejected { code: i32, msg: String },
DecodeError(SbeDecodeError),
Timeout(String),
UnknownRequestId(String),
}
impl Display for BinanceWsApiError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::ClientError(msg) => write!(f, "Client error: {msg}"),
Self::HandlerUnavailable(msg) => write!(f, "Handler unavailable: {msg}"),
Self::ConnectionError(msg) => write!(f, "Connection error: {msg}"),
Self::AuthenticationError(msg) => write!(f, "Authentication error: {msg}"),
Self::RequestRejected { code, msg } => {
write!(f, "Request rejected [{code}]: {msg}")
}
Self::DecodeError(err) => write!(f, "Decode error: {err}"),
Self::Timeout(msg) => write!(f, "Timeout: {msg}"),
Self::UnknownRequestId(id) => write!(f, "Unknown request ID: {id}"),
}
}
}
impl std::error::Error for BinanceWsApiError {}
impl From<SbeDecodeError> for BinanceWsApiError {
fn from(err: SbeDecodeError) -> Self {
Self::DecodeError(err)
}
}
pub type BinanceWsApiResult<T> = Result<T, BinanceWsApiError>;