2018-10-23 03:18:05 +02:00
|
|
|
//! Http client request
|
|
|
|
use std::io;
|
|
|
|
|
|
|
|
use actix_net::connector::ConnectorError;
|
2018-12-06 23:32:52 +01:00
|
|
|
use failure::Fail;
|
|
|
|
use http::{header::HeaderValue, Error as HttpError, StatusCode};
|
2018-10-23 03:18:05 +02:00
|
|
|
|
2018-12-06 23:32:52 +01:00
|
|
|
use crate::error::ParseError;
|
|
|
|
use crate::ws::ProtocolError;
|
2018-10-23 03:18:05 +02:00
|
|
|
|
|
|
|
/// Websocket client error
|
|
|
|
#[derive(Fail, Debug)]
|
|
|
|
pub enum ClientError {
|
|
|
|
/// Invalid url
|
|
|
|
#[fail(display = "Invalid url")]
|
|
|
|
InvalidUrl,
|
|
|
|
/// Invalid response status
|
|
|
|
#[fail(display = "Invalid response status")]
|
|
|
|
InvalidResponseStatus(StatusCode),
|
|
|
|
/// Invalid upgrade header
|
|
|
|
#[fail(display = "Invalid upgrade header")]
|
|
|
|
InvalidUpgradeHeader,
|
|
|
|
/// Invalid connection header
|
|
|
|
#[fail(display = "Invalid connection header")]
|
|
|
|
InvalidConnectionHeader(HeaderValue),
|
|
|
|
/// Missing CONNECTION header
|
|
|
|
#[fail(display = "Missing CONNECTION header")]
|
|
|
|
MissingConnectionHeader,
|
|
|
|
/// Missing SEC-WEBSOCKET-ACCEPT header
|
|
|
|
#[fail(display = "Missing SEC-WEBSOCKET-ACCEPT header")]
|
|
|
|
MissingWebSocketAcceptHeader,
|
|
|
|
/// Invalid challenge response
|
|
|
|
#[fail(display = "Invalid challenge response")]
|
|
|
|
InvalidChallengeResponse(String, HeaderValue),
|
|
|
|
/// Http parsing error
|
|
|
|
#[fail(display = "Http parsing error")]
|
2018-11-28 20:10:13 +01:00
|
|
|
Http(#[cause] HttpError),
|
2018-10-23 03:18:05 +02:00
|
|
|
/// Response parsing error
|
2018-11-28 20:02:31 +01:00
|
|
|
#[fail(display = "Response parsing error: {}", _0)]
|
2018-11-28 20:10:13 +01:00
|
|
|
ParseError(#[cause] ParseError),
|
2018-10-23 03:18:05 +02:00
|
|
|
/// Protocol error
|
|
|
|
#[fail(display = "{}", _0)]
|
|
|
|
Protocol(#[cause] ProtocolError),
|
|
|
|
/// Connect error
|
2018-11-28 20:10:13 +01:00
|
|
|
#[fail(display = "Connector error: {:?}", _0)]
|
2018-10-23 03:18:05 +02:00
|
|
|
Connect(ConnectorError),
|
|
|
|
/// IO Error
|
|
|
|
#[fail(display = "{}", _0)]
|
2018-11-28 20:10:13 +01:00
|
|
|
Io(#[cause] io::Error),
|
2018-10-23 03:18:05 +02:00
|
|
|
/// "Disconnected"
|
|
|
|
#[fail(display = "Disconnected")]
|
|
|
|
Disconnected,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<HttpError> for ClientError {
|
|
|
|
fn from(err: HttpError) -> ClientError {
|
|
|
|
ClientError::Http(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<ConnectorError> for ClientError {
|
|
|
|
fn from(err: ConnectorError) -> ClientError {
|
|
|
|
ClientError::Connect(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<ProtocolError> for ClientError {
|
|
|
|
fn from(err: ProtocolError) -> ClientError {
|
|
|
|
ClientError::Protocol(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<io::Error> for ClientError {
|
|
|
|
fn from(err: io::Error) -> ClientError {
|
|
|
|
ClientError::Io(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<ParseError> for ClientError {
|
|
|
|
fn from(err: ParseError) -> ClientError {
|
|
|
|
ClientError::ParseError(err)
|
|
|
|
}
|
|
|
|
}
|