pub use actix_http::{
error::{HttpError, PayloadError},
header::HeaderValue,
ws::{HandshakeError as WsHandshakeError, ProtocolError as WsProtocolError},
StatusCode,
};
use derive_more::{Display, From};
use serde_json::error::Error as JsonError;
pub use crate::client::{ConnectError, FreezeRequestError, InvalidUrl, SendRequestError};
#[derive(Debug, Display, From)]
pub enum WsClientError {
#[display(fmt = "Invalid response status")]
InvalidResponseStatus(StatusCode),
#[display(fmt = "Invalid upgrade header")]
InvalidUpgradeHeader,
#[display(fmt = "Invalid connection header")]
InvalidConnectionHeader(HeaderValue),
#[display(fmt = "Missing Connection header")]
MissingConnectionHeader,
#[display(fmt = "Missing Sec-Websocket-Accept header")]
MissingWebSocketAcceptHeader,
#[display(fmt = "Invalid challenge response")]
InvalidChallengeResponse([u8; 28], HeaderValue),
#[display(fmt = "{}", _0)]
Protocol(WsProtocolError),
#[display(fmt = "{}", _0)]
SendRequest(SendRequestError),
}
impl std::error::Error for WsClientError {}
impl From<InvalidUrl> for WsClientError {
fn from(err: InvalidUrl) -> Self {
WsClientError::SendRequest(err.into())
}
}
impl From<HttpError> for WsClientError {
fn from(err: HttpError) -> Self {
WsClientError::SendRequest(err.into())
}
}
#[derive(Debug, Display, From)]
pub enum JsonPayloadError {
#[display(fmt = "Content type error")]
ContentType,
#[display(fmt = "Json deserialize error: {}", _0)]
Deserialize(JsonError),
#[display(fmt = "Error that occur during reading payload: {}", _0)]
Payload(PayloadError),
}
impl std::error::Error for JsonPayloadError {}