actix_tls/connect/
error.rs

1use std::{error::Error, fmt, io};
2
3/// Errors that can result from using a connector service.
4#[derive(Debug)]
5pub enum ConnectError {
6    /// Failed to resolve the hostname.
7    Resolver(Box<dyn std::error::Error>),
8
9    /// No DNS records.
10    NoRecords,
11
12    /// Invalid input.
13    InvalidInput,
14
15    /// Unresolved host name.
16    Unresolved,
17
18    /// Connection IO error.
19    Io(io::Error),
20}
21
22impl fmt::Display for ConnectError {
23    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24        match self {
25            Self::NoRecords => f.write_str("No DNS records found for the input"),
26            Self::InvalidInput => f.write_str("Invalid input"),
27            Self::Unresolved => {
28                f.write_str("Connector received `Connect` method with unresolved host")
29            }
30            Self::Resolver(_) => f.write_str("Failed to resolve hostname"),
31            Self::Io(_) => f.write_str("I/O error"),
32        }
33    }
34}
35
36impl Error for ConnectError {
37    fn source(&self) -> Option<&(dyn Error + 'static)> {
38        match self {
39            Self::Resolver(err) => Some(&**err),
40            Self::Io(err) => Some(err),
41            Self::NoRecords | Self::InvalidInput | Self::Unresolved => None,
42        }
43    }
44}