1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-12-02 19:32:24 +01:00
actix-web/awc/src/client/error.rs

158 lines
4.2 KiB
Rust
Raw Normal View History

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
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)]
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
#[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")]
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
}
impl std::error::Error for ConnectError {}
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 {
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),
}
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
#[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
impl std::error::Error for SendRequestError {}
/// 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]
pub enum FreezeRequestError {
/// Invalid URL
#[display(fmt = "Invalid URL: {}", _0)]
Url(InvalidUrl),
2021-02-11 23:39:54 +01:00
/// HTTP error
#[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>),
}
impl std::error::Error for FreezeRequestError {}
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-12 17:52:46 +02:00
}