use prost::DecodeError;
use tokio_tungstenite::tungstenite::protocol::frame::coding::CloseCode;
#[derive(Debug)]
pub struct WsCloseReason {
pub code: CloseCode,
pub message: String,
}
#[derive(Debug)]
pub struct WsResponseErrorDetail {
pub code: u64,
pub msg: String,
}
#[derive(Debug, thiserror::Error)]
pub enum WsClientError {
#[error("unexpected response")]
UnexpectedResponse,
#[error("decode message error")]
Decode(#[from] DecodeError),
#[error("connect timeout")]
ConnectTimeout,
#[error("request timeout")]
RequestTimeout,
#[error("connection closed")]
ConnectionClosed {
reason: Option<WsCloseReason>,
},
#[error("Client is closed")]
ClientClosed,
#[error("response error: {status}: detail:{detail:?}")]
ResponseError {
status: u8,
detail: Option<WsResponseErrorDetail>,
},
#[error("cancelled")]
Cancelled,
#[error(transparent)]
InvalidUrl(#[from] url::ParseError),
#[error(transparent)]
Websocket(#[from] tokio_tungstenite::tungstenite::Error),
}
pub type WsClientResult<T, E = WsClientError> = std::result::Result<T, E>;