2021-12-04 20:40:47 +01:00
|
|
|
use std::{fmt, io};
|
2018-11-12 08:12:54 +01:00
|
|
|
|
2018-12-20 03:34:56 +01:00
|
|
|
use derive_more::{Display, From};
|
2018-11-12 08:12:54 +01:00
|
|
|
|
2021-12-05 15:37:20 +01:00
|
|
|
use actix_http::error::{HttpError, ParseError};
|
2021-12-04 20:40:47 +01:00
|
|
|
|
2019-11-19 13:54:19 +01:00
|
|
|
#[cfg(feature = "openssl")]
|
2021-12-04 20:40:47 +01:00
|
|
|
use actix_tls::accept::openssl::reexports::Error as OpensslError;
|
|
|
|
|
|
|
|
use crate::BoxError;
|
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)]
|
2021-06-17 18:57:58 +02:00
|
|
|
#[non_exhaustive]
|
2019-03-13 22:41:40 +01:00
|
|
|
pub enum ConnectError {
|
2018-11-12 08:12:54 +01:00
|
|
|
/// 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
|
2019-11-19 13:54:19 +01:00
|
|
|
#[cfg(feature = "openssl")]
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "{}", _0)]
|
2021-12-04 20:40:47 +01:00
|
|
|
SslError(OpensslError),
|
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)]
|
2021-02-07 02:00:40 +01:00
|
|
|
Resolver(Box<dyn std::error::Error>),
|
2018-11-12 08:12:54 +01:00
|
|
|
|
|
|
|
/// No dns records
|
2021-02-16 10:08:30 +01:00
|
|
|
#[display(fmt = "No DNS records found for the input")]
|
2018-11-12 08:12:54 +01:00
|
|
|
NoRecords,
|
|
|
|
|
2019-01-29 05:41:09 +01:00
|
|
|
/// Http2 error
|
|
|
|
#[display(fmt = "{}", _0)]
|
|
|
|
H2(h2::Error),
|
|
|
|
|
2018-11-12 08:12:54 +01:00
|
|
|
/// Connecting took too long
|
2020-06-02 19:04:49 +02:00
|
|
|
#[display(fmt = "Timeout 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,
|
|
|
|
|
2019-03-13 22:41:40 +01:00
|
|
|
/// Unresolved host name
|
|
|
|
#[display(fmt = "Connector received `Connect` method with unresolved host")]
|
2020-05-07 19:26:48 +02:00
|
|
|
Unresolved,
|
2019-03-13 22:41:40 +01:00
|
|
|
|
2018-11-12 08:12:54 +01:00
|
|
|
/// 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
|
|
|
}
|
|
|
|
|
2020-03-18 02:51:06 +01:00
|
|
|
impl std::error::Error for ConnectError {}
|
|
|
|
|
2021-01-04 00:47:04 +01:00
|
|
|
impl From<actix_tls::connect::ConnectError> for ConnectError {
|
|
|
|
fn from(err: actix_tls::connect::ConnectError) -> ConnectError {
|
2019-03-13 22:41:40 +01:00
|
|
|
match err {
|
2021-01-04 00:47:04 +01:00
|
|
|
actix_tls::connect::ConnectError::Resolver(e) => ConnectError::Resolver(e),
|
|
|
|
actix_tls::connect::ConnectError::NoRecords => ConnectError::NoRecords,
|
|
|
|
actix_tls::connect::ConnectError::InvalidInput => panic!(),
|
|
|
|
actix_tls::connect::ConnectError::Unresolved => ConnectError::Unresolved,
|
|
|
|
actix_tls::connect::ConnectError::Io(e) => ConnectError::Io(e),
|
2019-03-13 22:41:40 +01:00
|
|
|
}
|
|
|
|
}
|
2018-11-12 08:12:54 +01:00
|
|
|
}
|
|
|
|
|
2019-03-13 22:41:40 +01:00
|
|
|
#[derive(Debug, Display, From)]
|
2021-06-17 18:57:58 +02:00
|
|
|
#[non_exhaustive]
|
2019-03-13 22:41:40 +01:00
|
|
|
pub enum InvalidUrl {
|
2021-02-11 23:39:54 +01:00
|
|
|
#[display(fmt = "Missing URL scheme")]
|
2019-03-13 22:41:40 +01:00
|
|
|
MissingScheme,
|
2021-02-11 23:39:54 +01:00
|
|
|
|
|
|
|
#[display(fmt = "Unknown URL scheme")]
|
2019-03-13 22:41:40 +01:00
|
|
|
UnknownScheme,
|
2021-02-11 23:39:54 +01:00
|
|
|
|
2019-03-13 22:41:40 +01:00
|
|
|
#[display(fmt = "Missing host name")]
|
|
|
|
MissingHost,
|
2021-02-11 23:39:54 +01:00
|
|
|
|
|
|
|
#[display(fmt = "URL parse error: {}", _0)]
|
2019-03-13 22:41:40 +01:00
|
|
|
HttpError(http::Error),
|
|
|
|
}
|
|
|
|
|
2020-03-18 02:51:06 +01:00
|
|
|
impl std::error::Error for InvalidUrl {}
|
|
|
|
|
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)]
|
2021-06-17 18:57:58 +02:00
|
|
|
#[non_exhaustive]
|
2018-11-14 07:53:30 +01:00
|
|
|
pub enum SendRequestError {
|
2019-03-13 22:41:40 +01:00
|
|
|
/// Invalid URL
|
|
|
|
#[display(fmt = "Invalid URL: {}", _0)]
|
|
|
|
Url(InvalidUrl),
|
2021-02-11 23:39:54 +01:00
|
|
|
|
2018-11-14 07:53:30 +01:00
|
|
|
/// Failed to connect to host
|
2018-12-20 03:34:56 +01:00
|
|
|
#[display(fmt = "Failed to connect to host: {}", _0)]
|
2019-03-13 22:41:40 +01:00
|
|
|
Connect(ConnectError),
|
2021-02-11 23:39:54 +01:00
|
|
|
|
2018-11-14 07:53:30 +01:00
|
|
|
/// Error sending request
|
|
|
|
Send(io::Error),
|
2021-02-11 23:39:54 +01:00
|
|
|
|
2018-11-14 07:53:30 +01:00
|
|
|
/// Error parsing response
|
|
|
|
Response(ParseError),
|
2021-02-11 23:39:54 +01:00
|
|
|
|
2019-03-26 05:52:45 +01:00
|
|
|
/// Http error
|
|
|
|
#[display(fmt = "{}", _0)]
|
|
|
|
Http(HttpError),
|
2021-02-11 23:39:54 +01:00
|
|
|
|
2019-01-29 05:41:09 +01:00
|
|
|
/// Http2 error
|
|
|
|
#[display(fmt = "{}", _0)]
|
|
|
|
H2(h2::Error),
|
2021-02-11 23:39:54 +01:00
|
|
|
|
2019-03-29 06:33:41 +01:00
|
|
|
/// Response took too long
|
2020-06-02 19:04:49 +02:00
|
|
|
#[display(fmt = "Timeout while waiting for response")]
|
2019-03-29 06:33:41 +01:00
|
|
|
Timeout,
|
2021-02-11 23:39:54 +01:00
|
|
|
|
|
|
|
/// Tunnels are not supported for HTTP/2 connection
|
2019-03-28 02:53:19 +01:00
|
|
|
#[display(fmt = "Tunnels are not supported for http2 connection")]
|
|
|
|
TunnelNotSupported,
|
2021-02-11 23:39:54 +01:00
|
|
|
|
2018-11-14 07:53:30 +01:00
|
|
|
/// Error sending request body
|
2021-12-04 20:40:47 +01:00
|
|
|
Body(BoxError),
|
2021-06-17 18:57:58 +02:00
|
|
|
|
|
|
|
/// Other errors that can occur after submitting a request.
|
|
|
|
#[display(fmt = "{:?}: {}", _1, _0)]
|
2021-12-04 20:40:47 +01:00
|
|
|
Custom(BoxError, Box<dyn fmt::Debug>),
|
2018-11-14 07:53:30 +01:00
|
|
|
}
|
2019-01-29 05:41:09 +01:00
|
|
|
|
2020-03-18 02:51:06 +01:00
|
|
|
impl std::error::Error for SendRequestError {}
|
|
|
|
|
2019-09-10 06:29:32 +02:00
|
|
|
/// A set of errors that can occur during freezing a request
|
|
|
|
#[derive(Debug, Display, From)]
|
2021-06-17 18:57:58 +02:00
|
|
|
#[non_exhaustive]
|
2019-09-10 06:29:32 +02:00
|
|
|
pub enum FreezeRequestError {
|
|
|
|
/// Invalid URL
|
|
|
|
#[display(fmt = "Invalid URL: {}", _0)]
|
|
|
|
Url(InvalidUrl),
|
2021-02-11 23:39:54 +01:00
|
|
|
|
|
|
|
/// HTTP error
|
2019-09-10 06:29:32 +02:00
|
|
|
#[display(fmt = "{}", _0)]
|
|
|
|
Http(HttpError),
|
2021-06-17 18:57:58 +02:00
|
|
|
|
|
|
|
/// Other errors that can occur after submitting a request.
|
|
|
|
#[display(fmt = "{:?}: {}", _1, _0)]
|
2021-12-04 20:40:47 +01:00
|
|
|
Custom(BoxError, Box<dyn fmt::Debug>),
|
2019-09-10 06:29:32 +02:00
|
|
|
}
|
|
|
|
|
2020-03-18 02:51:06 +01:00
|
|
|
impl std::error::Error for FreezeRequestError {}
|
|
|
|
|
2019-09-10 06:29:32 +02:00
|
|
|
impl From<FreezeRequestError> for SendRequestError {
|
2021-06-17 18:57:58 +02:00
|
|
|
fn from(err: FreezeRequestError) -> Self {
|
|
|
|
match err {
|
|
|
|
FreezeRequestError::Url(err) => err.into(),
|
|
|
|
FreezeRequestError::Http(err) => err.into(),
|
|
|
|
FreezeRequestError::Custom(err, msg) => SendRequestError::Custom(err, msg),
|
2019-09-10 06:29:32 +02:00
|
|
|
}
|
|
|
|
}
|
2019-09-12 17:52:46 +02:00
|
|
|
}
|