1
0
mirror of https://github.com/fafhrd91/actix-net synced 2025-03-20 06:45:17 +01:00

45 lines
1.2 KiB
Rust
Raw Normal View History

use std::{error::Error, fmt, io};
2019-03-13 12:40:11 -07:00
/// Errors that can result from using a connector service.
#[derive(Debug)]
2019-03-13 12:40:11 -07:00
pub enum ConnectError {
/// Failed to resolve the hostname.
Resolver(Box<dyn std::error::Error>),
2019-03-13 12:40:11 -07:00
/// No DNS records.
2019-03-13 12:40:11 -07:00
NoRecords,
/// Invalid input.
2019-03-13 12:40:11 -07:00
InvalidInput,
/// Unresolved host name.
Unresolved,
2019-03-13 12:40:11 -07:00
/// Connection IO error.
2019-03-13 14:38:33 -07:00
Io(io::Error),
2019-03-13 12:40:11 -07:00
}
impl fmt::Display for ConnectError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NoRecords => f.write_str("No DNS records found for the input"),
Self::InvalidInput => f.write_str("Invalid input"),
Self::Unresolved => {
f.write_str("Connector received `Connect` method with unresolved host")
}
Self::Resolver(_) => f.write_str("Failed to resolve hostname"),
Self::Io(_) => f.write_str("I/O error"),
}
}
}
impl Error for ConnectError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::Resolver(err) => Some(&**err),
Self::Io(err) => Some(err),
Self::NoRecords | Self::InvalidInput | Self::Unresolved => None,
}
}
}