2019-03-28 01:53:19 +00:00
|
|
|
//! Http client errors
|
|
|
|
pub use actix_http::client::{ConnectError, InvalidUrl, SendRequestError};
|
|
|
|
pub use actix_http::error::PayloadError;
|
2019-03-29 20:49:21 +00:00
|
|
|
pub use actix_http::ws::HandshakeError as WsHandshakeError;
|
2019-03-28 01:53:19 +00:00
|
|
|
pub use actix_http::ws::ProtocolError as WsProtocolError;
|
2018-10-23 01:18:05 +00:00
|
|
|
|
2019-04-01 18:51:18 +00:00
|
|
|
use actix_http::{Response, ResponseError};
|
|
|
|
use serde_json::error::Error as JsonError;
|
|
|
|
|
2019-03-28 01:53:19 +00:00
|
|
|
use actix_http::http::{header::HeaderValue, Error as HttpError, StatusCode};
|
2018-12-20 02:34:56 +00:00
|
|
|
use derive_more::{Display, From};
|
2018-10-23 01:18:05 +00:00
|
|
|
|
|
|
|
/// 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 {
|
2018-10-23 01:18:05 +00:00
|
|
|
/// Invalid response status
|
2018-12-20 02:34:56 +00:00
|
|
|
#[display(fmt = "Invalid response status")]
|
2018-10-23 01:18:05 +00:00
|
|
|
InvalidResponseStatus(StatusCode),
|
|
|
|
/// Invalid upgrade header
|
2018-12-20 02:34:56 +00:00
|
|
|
#[display(fmt = "Invalid upgrade header")]
|
2018-10-23 01:18:05 +00:00
|
|
|
InvalidUpgradeHeader,
|
|
|
|
/// Invalid connection header
|
2018-12-20 02:34:56 +00:00
|
|
|
#[display(fmt = "Invalid connection header")]
|
2018-10-23 01:18:05 +00:00
|
|
|
InvalidConnectionHeader(HeaderValue),
|
|
|
|
/// Missing CONNECTION header
|
2018-12-20 02:34:56 +00:00
|
|
|
#[display(fmt = "Missing CONNECTION header")]
|
2018-10-23 01:18:05 +00:00
|
|
|
MissingConnectionHeader,
|
|
|
|
/// Missing SEC-WEBSOCKET-ACCEPT header
|
2018-12-20 02:34:56 +00:00
|
|
|
#[display(fmt = "Missing SEC-WEBSOCKET-ACCEPT header")]
|
2018-10-23 01:18:05 +00:00
|
|
|
MissingWebSocketAcceptHeader,
|
|
|
|
/// Invalid challenge response
|
2018-12-20 02:34:56 +00:00
|
|
|
#[display(fmt = "Invalid challenge response")]
|
2018-10-23 01:18:05 +00:00
|
|
|
InvalidChallengeResponse(String, HeaderValue),
|
|
|
|
/// Protocol error
|
2018-12-20 02:34:56 +00:00
|
|
|
#[display(fmt = "{}", _0)]
|
2019-03-28 01:53:19 +00:00
|
|
|
Protocol(WsProtocolError),
|
|
|
|
/// 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 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-23 01:18:05 +00:00
|
|
|
}
|
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),
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return `InternlaServerError` for `JsonPayloadError`
|
|
|
|
impl ResponseError for JsonPayloadError {
|
|
|
|
fn error_response(&self) -> Response {
|
|
|
|
Response::new(StatusCode::INTERNAL_SERVER_ERROR)
|
|
|
|
}
|
|
|
|
}
|