2018-11-12 08:12:54 +01:00
|
|
|
use std::io;
|
|
|
|
|
2018-12-20 03:34:56 +01:00
|
|
|
use derive_more::{Display, From};
|
2018-11-12 08:12:54 +01:00
|
|
|
use trust_dns_resolver::error::ResolveError;
|
|
|
|
|
|
|
|
#[cfg(feature = "ssl")]
|
2018-12-11 03:08:33 +01:00
|
|
|
use openssl::ssl::{Error as SslError, HandshakeError};
|
2018-11-12 08:12:54 +01:00
|
|
|
|
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
|
2018-12-20 03:34:56 +01:00
|
|
|
#[derive(Debug, Display, From)]
|
2018-11-12 08:12:54 +01:00
|
|
|
pub enum ConnectorError {
|
|
|
|
/// Invalid URL
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "Invalid URL")]
|
2018-11-12 08:12:54 +01:00
|
|
|
InvalidUrl(InvalidUrlKind),
|
|
|
|
|
|
|
|
/// SSL feature is not enabled
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "SSL is not supported")]
|
2018-11-12 08:12:54 +01:00
|
|
|
SslIsNotSupported,
|
|
|
|
|
|
|
|
/// SSL error
|
2018-12-11 03:08:33 +01:00
|
|
|
#[cfg(feature = "ssl")]
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "{}", _0)]
|
|
|
|
SslError(SslError),
|
2018-11-12 08:12:54 +01:00
|
|
|
|
|
|
|
/// Failed to resolve the hostname
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "Failed resolving hostname: {}", _0)]
|
2018-11-12 08:12:54 +01:00
|
|
|
Resolver(ResolveError),
|
|
|
|
|
|
|
|
/// No dns records
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "No dns records found for the input")]
|
2018-11-12 08:12:54 +01:00
|
|
|
NoRecords,
|
|
|
|
|
|
|
|
/// Connecting took too long
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "Timeout out while establishing connection")]
|
2018-11-12 08:12:54 +01:00
|
|
|
Timeout,
|
|
|
|
|
|
|
|
/// Connector has been disconnected
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "Internal error: connector has been disconnected")]
|
2018-11-12 08:12:54 +01:00
|
|
|
Disconnected,
|
|
|
|
|
|
|
|
/// Connection io error
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "{}", _0)]
|
|
|
|
Io(io::Error),
|
2018-11-12 08:12:54 +01:00
|
|
|
}
|
|
|
|
|
2018-12-20 03:34:56 +01:00
|
|
|
#[derive(Debug, Display)]
|
2018-11-12 08:12:54 +01:00
|
|
|
pub enum InvalidUrlKind {
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "Missing url scheme")]
|
2018-11-12 08:12:54 +01:00
|
|
|
MissingScheme,
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "Unknown url scheme")]
|
2018-11-12 08:12:54 +01:00
|
|
|
UnknownScheme,
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "Missing host name")]
|
2018-11-12 08:12:54 +01:00
|
|
|
MissingHost,
|
|
|
|
}
|
|
|
|
|
2018-12-11 03:08:33 +01:00
|
|
|
#[cfg(feature = "ssl")]
|
|
|
|
impl<T> From<HandshakeError<T>> for ConnectorError {
|
|
|
|
fn from(err: HandshakeError<T>) -> ConnectorError {
|
|
|
|
match err {
|
|
|
|
HandshakeError::SetupFailure(stack) => SslError::from(stack).into(),
|
|
|
|
HandshakeError::Failure(stream) => {
|
|
|
|
SslError::from(stream.into_error()).into()
|
|
|
|
}
|
|
|
|
HandshakeError::WouldBlock(stream) => {
|
|
|
|
SslError::from(stream.into_error()).into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-14 07:53:30 +01:00
|
|
|
/// A set of errors that can occur during request sending and response reading
|
2018-12-20 03:34:56 +01:00
|
|
|
#[derive(Debug, Display, From)]
|
2018-11-14 07:53:30 +01:00
|
|
|
pub enum SendRequestError {
|
|
|
|
/// Failed to connect to host
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "Failed to connect to host: {}", _0)]
|
2018-11-14 07:53:30 +01:00
|
|
|
Connector(ConnectorError),
|
|
|
|
/// Error sending request
|
|
|
|
Send(io::Error),
|
|
|
|
/// Error parsing response
|
|
|
|
Response(ParseError),
|
|
|
|
/// Error sending request body
|
|
|
|
Body(Error),
|
|
|
|
}
|