use std::{fmt, io};
use actix_http::error::{HttpError, ParseError};
#[cfg(feature = "openssl")]
use actix_tls::accept::openssl::reexports::Error as OpensslError;
use derive_more::{Display, From};
use crate::BoxError;
#[derive(Debug, Display, From)]
#[non_exhaustive]
pub enum ConnectError {
#[display(fmt = "SSL is not supported")]
SslIsNotSupported,
#[cfg(feature = "openssl")]
#[display(fmt = "{}", _0)]
SslError(OpensslError),
#[display(fmt = "Failed resolving hostname: {}", _0)]
Resolver(Box<dyn std::error::Error>),
#[display(fmt = "No DNS records found for the input")]
NoRecords,
#[display(fmt = "{}", _0)]
H2(h2::Error),
#[display(fmt = "Timeout while establishing connection")]
Timeout,
#[display(fmt = "Internal error: connector has been disconnected")]
Disconnected,
#[display(fmt = "Connector received `Connect` method with unresolved host")]
Unresolved,
#[display(fmt = "{}", _0)]
Io(io::Error),
}
impl std::error::Error for ConnectError {}
impl From<actix_tls::connect::ConnectError> for ConnectError {
fn from(err: actix_tls::connect::ConnectError) -> ConnectError {
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),
}
}
}
#[derive(Debug, Display, From)]
#[non_exhaustive]
pub enum InvalidUrl {
#[display(fmt = "Missing URL scheme")]
MissingScheme,
#[display(fmt = "Unknown URL scheme")]
UnknownScheme,
#[display(fmt = "Missing host name")]
MissingHost,
#[display(fmt = "URL parse error: {}", _0)]
HttpError(http::Error),
}
impl std::error::Error for InvalidUrl {}
#[derive(Debug, Display, From)]
#[non_exhaustive]
pub enum SendRequestError {
#[display(fmt = "Invalid URL: {}", _0)]
Url(InvalidUrl),
#[display(fmt = "Failed to connect to host: {}", _0)]
Connect(ConnectError),
Send(io::Error),
Response(ParseError),
#[display(fmt = "{}", _0)]
Http(HttpError),
#[display(fmt = "{}", _0)]
H2(h2::Error),
#[display(fmt = "Timeout while waiting for response")]
Timeout,
#[display(fmt = "Tunnels are not supported for http2 connection")]
TunnelNotSupported,
Body(BoxError),
#[display(fmt = "{:?}: {}", _1, _0)]
Custom(BoxError, Box<dyn fmt::Debug>),
}
impl std::error::Error for SendRequestError {}
#[derive(Debug, Display, From)]
#[non_exhaustive]
pub enum FreezeRequestError {
#[display(fmt = "Invalid URL: {}", _0)]
Url(InvalidUrl),
#[display(fmt = "{}", _0)]
Http(HttpError),
#[display(fmt = "{:?}: {}", _1, _0)]
Custom(BoxError, Box<dyn fmt::Debug>),
}
impl std::error::Error for FreezeRequestError {}
impl From<FreezeRequestError> for SendRequestError {
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),
}
}
}