1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-25 08:52:42 +01:00
actix-web/src/client/error.rs

113 lines
2.9 KiB
Rust
Raw Normal View History

2018-11-12 08:12:54 +01:00
use std::io;
2018-12-06 23:32:52 +01:00
use failure::Fail;
2018-11-12 08:12:54 +01:00
use trust_dns_resolver::error::ResolveError;
#[cfg(feature = "ssl")]
use openssl::ssl::Error as SslError;
2018-12-06 23:32:52 +01:00
#[cfg(all(feature = "tls", not(any(feature = "ssl", feature = "rust-tls"))))]
2018-11-12 08:12:54 +01:00
use native_tls::Error as SslError;
2018-12-06 23:32:52 +01:00
#[cfg(all(feature = "rust-tls", not(any(feature = "tls", feature = "ssl"))))]
2018-11-12 08:12:54 +01:00
use std::io::Error as SslError;
2018-12-06 23:32:52 +01:00
use crate::error::{Error, ParseError};
2018-11-14 07:53:30 +01:00
2018-11-12 08:12:54 +01:00
/// A set of errors that can occur while connecting to an HTTP host
#[derive(Fail, Debug)]
pub enum ConnectorError {
/// Invalid URL
#[fail(display = "Invalid URL")]
InvalidUrl(InvalidUrlKind),
/// SSL feature is not enabled
#[fail(display = "SSL is not supported")]
SslIsNotSupported,
/// SSL error
#[cfg(any(feature = "tls", feature = "ssl", feature = "rust-tls"))]
#[fail(display = "{}", _0)]
SslError(#[cause] SslError),
/// Failed to resolve the hostname
#[fail(display = "Failed resolving hostname: {}", _0)]
Resolver(ResolveError),
/// No dns records
#[fail(display = "No dns records found for the input")]
NoRecords,
/// Connecting took too long
#[fail(display = "Timeout out while establishing connection")]
Timeout,
/// Connector has been disconnected
#[fail(display = "Internal error: connector has been disconnected")]
Disconnected,
/// Connection io error
#[fail(display = "{}", _0)]
IoError(io::Error),
}
#[derive(Fail, Debug)]
pub enum InvalidUrlKind {
#[fail(display = "Missing url scheme")]
MissingScheme,
#[fail(display = "Unknown url scheme")]
UnknownScheme,
#[fail(display = "Missing host name")]
MissingHost,
}
impl From<io::Error> for ConnectorError {
fn from(err: io::Error) -> ConnectorError {
ConnectorError::IoError(err)
}
}
impl From<ResolveError> for ConnectorError {
fn from(err: ResolveError) -> ConnectorError {
ConnectorError::Resolver(err)
}
}
2018-11-14 07:53:30 +01:00
/// A set of errors that can occur during request sending and response reading
#[derive(Debug)]
pub enum SendRequestError {
/// Failed to connect to host
// #[fail(display = "Failed to connect to host: {}", _0)]
Connector(ConnectorError),
/// Error sending request
Send(io::Error),
/// Error parsing response
Response(ParseError),
/// Error sending request body
Body(Error),
}
impl From<io::Error> for SendRequestError {
fn from(err: io::Error) -> SendRequestError {
SendRequestError::Send(err)
}
}
impl From<ConnectorError> for SendRequestError {
fn from(err: ConnectorError) -> SendRequestError {
SendRequestError::Connector(err)
}
}
impl From<ParseError> for SendRequestError {
fn from(err: ParseError) -> SendRequestError {
SendRequestError::Response(err)
}
}
impl From<Error> for SendRequestError {
fn from(err: Error) -> SendRequestError {
SendRequestError::Body(err)
}
}