1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-27 17:52:56 +01:00
actix-web/awc/src/error.rs

82 lines
2.3 KiB
Rust
Raw Normal View History

2021-02-15 13:20:43 +01:00
//! HTTP client errors
2021-12-25 03:28:23 +01:00
// TODO: figure out how best to expose http::Error vs actix_http::Error
pub use actix_http::{
error::{HttpError, PayloadError},
header::HeaderValue,
ws::{HandshakeError as WsHandshakeError, ProtocolError as WsProtocolError},
StatusCode,
};
use derive_more::{Display, From};
2019-04-01 20:51:18 +02:00
use serde_json::error::Error as JsonError;
pub use crate::client::{ConnectError, FreezeRequestError, InvalidUrl, SendRequestError};
2021-12-04 20:40:47 +01:00
// TODO: address display, error, and from impls
/// Websocket client error
2018-12-20 03:34:56 +01:00
#[derive(Debug, Display, From)]
2019-03-28 02:53:19 +01:00
pub enum WsClientError {
/// Invalid response status
2018-12-20 03:34:56 +01:00
#[display(fmt = "Invalid response status")]
InvalidResponseStatus(StatusCode),
2021-02-28 20:55:34 +01:00
/// Invalid upgrade header
2018-12-20 03:34:56 +01:00
#[display(fmt = "Invalid upgrade header")]
InvalidUpgradeHeader,
2021-02-28 20:55:34 +01:00
/// Invalid connection header
2018-12-20 03:34:56 +01:00
#[display(fmt = "Invalid connection header")]
InvalidConnectionHeader(HeaderValue),
2021-02-28 20:55:34 +01:00
/// Missing Connection header
#[display(fmt = "Missing Connection header")]
MissingConnectionHeader,
2021-02-28 20:55:34 +01:00
/// Missing Sec-Websocket-Accept header
#[display(fmt = "Missing Sec-Websocket-Accept header")]
MissingWebSocketAcceptHeader,
2021-02-28 20:55:34 +01:00
/// Invalid challenge response
2018-12-20 03:34:56 +01:00
#[display(fmt = "Invalid challenge response")]
2021-02-28 20:55:34 +01:00
InvalidChallengeResponse([u8; 28], HeaderValue),
/// Protocol error
2018-12-20 03:34:56 +01:00
#[display(fmt = "{}", _0)]
2019-03-28 02:53:19 +01:00
Protocol(WsProtocolError),
2021-02-28 20:55:34 +01:00
2019-03-28 02:53:19 +01:00
/// Send request error
2018-12-20 03:34:56 +01:00
#[display(fmt = "{}", _0)]
2019-03-28 02:53:19 +01:00
SendRequest(SendRequestError),
}
impl std::error::Error for WsClientError {}
2019-03-28 02:53:19 +01: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())
}
}
2019-04-01 20:51:18 +02: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),
}
impl std::error::Error for JsonPayloadError {}