62 lines
1.5 KiB
Rust
62 lines
1.5 KiB
Rust
use {
|
|
crate::prelude::{ParseRequestError, ParseResponseError},
|
|
std::{fmt, io},
|
|
};
|
|
|
|
#[derive(Debug)]
|
|
/// Errors which might occur when sending a message
|
|
pub enum Error {
|
|
DnsError,
|
|
TlsError(rustls::Error),
|
|
RequestError(ParseRequestError),
|
|
ResponseError(ParseResponseError),
|
|
IoError(io::Error),
|
|
}
|
|
|
|
impl fmt::Display for Error {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
Self::DnsError => write!(f, "Dns Error"),
|
|
Self::TlsError(e) => write!(f, "{e}"),
|
|
Self::RequestError(e) => write!(f, "{e}"),
|
|
Self::ResponseError(e) => write!(f, "{e}"),
|
|
Self::IoError(e) => write!(f, "{e}"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::error::Error for Error {
|
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
|
match self {
|
|
Self::DnsError => None,
|
|
Self::RequestError(e) => Some(e),
|
|
Self::ResponseError(e) => Some(e),
|
|
Self::TlsError(e) => Some(e),
|
|
Self::IoError(e) => Some(e),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<rustls::Error> for Error {
|
|
fn from(value: rustls::Error) -> Self {
|
|
Self::TlsError(value)
|
|
}
|
|
}
|
|
|
|
impl From<ParseRequestError> for Error {
|
|
fn from(value: ParseRequestError) -> Self {
|
|
Self::RequestError(value)
|
|
}
|
|
}
|
|
|
|
impl From<ParseResponseError> for Error {
|
|
fn from(value: ParseResponseError) -> Self {
|
|
Self::ResponseError(value)
|
|
}
|
|
}
|
|
|
|
impl From<io::Error> for Error {
|
|
fn from(value: io::Error) -> Self {
|
|
Self::IoError(value)
|
|
}
|
|
}
|