1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-20 23:26:44 +00:00
actix-web/awc/src/error.rs

83 lines
2.4 KiB
Rust
Raw Normal View History

2021-02-15 12:20:43 +00:00
//! HTTP client errors
2021-02-11 23:03:17 +00:00
pub use actix_http::client::{ConnectError, FreezeRequestError, InvalidUrl, SendRequestError};
2019-03-28 01:53:19 +00:00
pub use actix_http::error::PayloadError;
2019-12-05 17:35:43 +00:00
pub use actix_http::http::Error as HttpError;
pub use actix_http::ws::HandshakeError as WsHandshakeError;
2019-03-28 01:53:19 +00:00
pub use actix_http::ws::ProtocolError as WsProtocolError;
2019-11-26 10:07:39 +00:00
use actix_http::ResponseError;
2019-04-01 18:51:18 +00:00
use serde_json::error::Error as JsonError;
2019-12-05 17:35:43 +00:00
use actix_http::http::{header::HeaderValue, StatusCode};
2018-12-20 02:34:56 +00:00
use derive_more::{Display, From};
/// Websocket client error
2018-12-20 02:34:56 +00:00
#[derive(Debug, Display, From)]
2019-03-28 01:53:19 +00:00
pub enum WsClientError {
/// Invalid response status
2018-12-20 02:34:56 +00:00
#[display(fmt = "Invalid response status")]
InvalidResponseStatus(StatusCode),
2021-02-28 19:55:34 +00:00
/// Invalid upgrade header
2018-12-20 02:34:56 +00:00
#[display(fmt = "Invalid upgrade header")]
InvalidUpgradeHeader,
2021-02-28 19:55:34 +00:00
/// Invalid connection header
2018-12-20 02:34:56 +00:00
#[display(fmt = "Invalid connection header")]
InvalidConnectionHeader(HeaderValue),
2021-02-28 19:55:34 +00:00
/// Missing Connection header
#[display(fmt = "Missing Connection header")]
MissingConnectionHeader,
2021-02-28 19:55:34 +00:00
/// Missing Sec-Websocket-Accept header
#[display(fmt = "Missing Sec-Websocket-Accept header")]
MissingWebSocketAcceptHeader,
2021-02-28 19:55:34 +00:00
/// Invalid challenge response
2018-12-20 02:34:56 +00:00
#[display(fmt = "Invalid challenge response")]
2021-02-28 19:55:34 +00:00
InvalidChallengeResponse([u8; 28], HeaderValue),
/// Protocol error
2018-12-20 02:34:56 +00:00
#[display(fmt = "{}", _0)]
2019-03-28 01:53:19 +00:00
Protocol(WsProtocolError),
2021-02-28 19:55:34 +00:00
2019-03-28 01:53:19 +00:00
/// Send request error
2018-12-20 02:34:56 +00:00
#[display(fmt = "{}", _0)]
2019-03-28 01:53:19 +00:00
SendRequest(SendRequestError),
}
impl std::error::Error for WsClientError {}
2019-03-28 01:53:19 +00: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 18:51:18 +00: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 {}
/// Return `InternalServerError` for `JsonPayloadError`
2019-11-26 10:07:39 +00:00
impl ResponseError for JsonPayloadError {}