2018-10-23 03:18:05 +02:00
|
|
|
//! Http client request
|
|
|
|
use std::io;
|
|
|
|
|
2019-03-13 22:41:40 +01:00
|
|
|
use actix_connect::ConnectError;
|
2018-12-20 03:34:56 +01:00
|
|
|
use derive_more::{Display, From};
|
2018-12-06 23:32:52 +01:00
|
|
|
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
|
2018-12-20 03:34:56 +01:00
|
|
|
#[derive(Debug, Display, From)]
|
2018-10-23 03:18:05 +02:00
|
|
|
pub enum ClientError {
|
|
|
|
/// Invalid url
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "Invalid url")]
|
2018-10-23 03:18:05 +02:00
|
|
|
InvalidUrl,
|
|
|
|
/// Invalid response status
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "Invalid response status")]
|
2018-10-23 03:18:05 +02:00
|
|
|
InvalidResponseStatus(StatusCode),
|
|
|
|
/// Invalid upgrade header
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "Invalid upgrade header")]
|
2018-10-23 03:18:05 +02:00
|
|
|
InvalidUpgradeHeader,
|
|
|
|
/// Invalid connection header
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "Invalid connection header")]
|
2018-10-23 03:18:05 +02:00
|
|
|
InvalidConnectionHeader(HeaderValue),
|
|
|
|
/// Missing CONNECTION header
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "Missing CONNECTION header")]
|
2018-10-23 03:18:05 +02:00
|
|
|
MissingConnectionHeader,
|
|
|
|
/// Missing SEC-WEBSOCKET-ACCEPT header
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "Missing SEC-WEBSOCKET-ACCEPT header")]
|
2018-10-23 03:18:05 +02:00
|
|
|
MissingWebSocketAcceptHeader,
|
|
|
|
/// Invalid challenge response
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "Invalid challenge response")]
|
2018-10-23 03:18:05 +02:00
|
|
|
InvalidChallengeResponse(String, HeaderValue),
|
|
|
|
/// Http parsing error
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "Http parsing error")]
|
|
|
|
Http(HttpError),
|
2018-10-23 03:18:05 +02:00
|
|
|
/// Response parsing error
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "Response parsing error: {}", _0)]
|
|
|
|
ParseError(ParseError),
|
2018-10-23 03:18:05 +02:00
|
|
|
/// Protocol error
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "{}", _0)]
|
|
|
|
Protocol(ProtocolError),
|
2018-10-23 03:18:05 +02:00
|
|
|
/// Connect error
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "Connector error: {:?}", _0)]
|
2019-03-13 22:41:40 +01:00
|
|
|
Connect(ConnectError),
|
2018-10-23 03:18:05 +02:00
|
|
|
/// IO Error
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "{}", _0)]
|
|
|
|
Io(io::Error),
|
2018-10-23 03:18:05 +02:00
|
|
|
/// "Disconnected"
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "Disconnected")]
|
2018-10-23 03:18:05 +02:00
|
|
|
Disconnected,
|
|
|
|
}
|