2021-02-15 12:20:43 +00:00
|
|
|
//! HTTP client errors
|
|
|
|
|
2021-10-26 07:37:40 +08:00
|
|
|
pub use actix_http::{
|
2021-12-05 14:37:20 +00:00
|
|
|
error::{HttpError, PayloadError},
|
|
|
|
header::HeaderValue,
|
2021-10-26 07:37:40 +08:00
|
|
|
ws::{HandshakeError as WsHandshakeError, ProtocolError as WsProtocolError},
|
2021-12-05 14:37:20 +00:00
|
|
|
StatusCode,
|
2021-10-26 07:37:40 +08:00
|
|
|
};
|
2018-10-22 18:18:05 -07:00
|
|
|
|
2021-10-26 07:37:40 +08:00
|
|
|
use derive_more::{Display, From};
|
2019-04-01 11:51:18 -07:00
|
|
|
use serde_json::error::Error as JsonError;
|
|
|
|
|
2021-10-26 07:37:40 +08:00
|
|
|
pub use crate::client::{ConnectError, FreezeRequestError, InvalidUrl, SendRequestError};
|
2018-10-22 18:18:05 -07:00
|
|
|
|
2021-12-04 19:40:47 +00:00
|
|
|
// TODO: address display, error, and from impls
|
|
|
|
|
2018-10-22 18:18:05 -07:00
|
|
|
/// Websocket client error
|
2018-12-19 18:34:56 -08:00
|
|
|
#[derive(Debug, Display, From)]
|
2019-03-27 18:53:19 -07:00
|
|
|
pub enum WsClientError {
|
2018-10-22 18:18:05 -07:00
|
|
|
/// Invalid response status
|
2018-12-19 18:34:56 -08:00
|
|
|
#[display(fmt = "Invalid response status")]
|
2018-10-22 18:18:05 -07:00
|
|
|
InvalidResponseStatus(StatusCode),
|
2021-02-28 19:55:34 +00:00
|
|
|
|
2018-10-22 18:18:05 -07:00
|
|
|
/// Invalid upgrade header
|
2018-12-19 18:34:56 -08:00
|
|
|
#[display(fmt = "Invalid upgrade header")]
|
2018-10-22 18:18:05 -07:00
|
|
|
InvalidUpgradeHeader,
|
2021-02-28 19:55:34 +00:00
|
|
|
|
2018-10-22 18:18:05 -07:00
|
|
|
/// Invalid connection header
|
2018-12-19 18:34:56 -08:00
|
|
|
#[display(fmt = "Invalid connection header")]
|
2018-10-22 18:18:05 -07:00
|
|
|
InvalidConnectionHeader(HeaderValue),
|
2021-02-28 19:55:34 +00:00
|
|
|
|
|
|
|
/// Missing Connection header
|
|
|
|
#[display(fmt = "Missing Connection header")]
|
2018-10-22 18:18:05 -07:00
|
|
|
MissingConnectionHeader,
|
2021-02-28 19:55:34 +00:00
|
|
|
|
|
|
|
/// Missing Sec-Websocket-Accept header
|
|
|
|
#[display(fmt = "Missing Sec-Websocket-Accept header")]
|
2018-10-22 18:18:05 -07:00
|
|
|
MissingWebSocketAcceptHeader,
|
2021-02-28 19:55:34 +00:00
|
|
|
|
2018-10-22 18:18:05 -07:00
|
|
|
/// Invalid challenge response
|
2018-12-19 18:34:56 -08:00
|
|
|
#[display(fmt = "Invalid challenge response")]
|
2021-02-28 19:55:34 +00:00
|
|
|
InvalidChallengeResponse([u8; 28], HeaderValue),
|
|
|
|
|
2018-10-22 18:18:05 -07:00
|
|
|
/// Protocol error
|
2018-12-19 18:34:56 -08:00
|
|
|
#[display(fmt = "{}", _0)]
|
2019-03-27 18:53:19 -07:00
|
|
|
Protocol(WsProtocolError),
|
2021-02-28 19:55:34 +00:00
|
|
|
|
2019-03-27 18:53:19 -07:00
|
|
|
/// Send request error
|
2018-12-19 18:34:56 -08:00
|
|
|
#[display(fmt = "{}", _0)]
|
2019-03-27 18:53:19 -07:00
|
|
|
SendRequest(SendRequestError),
|
|
|
|
}
|
|
|
|
|
2020-03-17 22:51:06 -03:00
|
|
|
impl std::error::Error for WsClientError {}
|
|
|
|
|
2019-03-27 18:53:19 -07:00
|
|
|
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())
|
|
|
|
}
|
2018-10-22 18:18:05 -07:00
|
|
|
}
|
2019-04-01 11:51:18 -07:00
|
|
|
|
|
|
|
/// A set of errors that can occur during parsing json payloads
|
|
|
|
#[derive(Debug, Display, From)]
|
|
|
|
pub enum JsonPayloadError {
|
|
|
|
/// Content type error
|
|
|
|
#[display(fmt = "Content type error")]
|
|
|
|
ContentType,
|
|
|
|
/// Deserialize error
|
|
|
|
#[display(fmt = "Json deserialize error: {}", _0)]
|
|
|
|
Deserialize(JsonError),
|
|
|
|
/// Payload error
|
|
|
|
#[display(fmt = "Error that occur during reading payload: {}", _0)]
|
|
|
|
Payload(PayloadError),
|
|
|
|
}
|
|
|
|
|
2020-03-17 22:51:06 -03:00
|
|
|
impl std::error::Error for JsonPayloadError {}
|