You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.2 KiB
62 lines
1.2 KiB
//! Internal errors
|
|
use super::*;
|
|
use std::{
|
|
fmt,
|
|
error,
|
|
net::SocketAddr,
|
|
};
|
|
|
|
#[derive(Debug)]
|
|
#[non_exhaustive]
|
|
pub enum Error {
|
|
Denied(SocketAddr, bool),
|
|
TimeoutReached,
|
|
NoResponse,
|
|
Unknown,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct HandleError;
|
|
|
|
impl Error
|
|
{
|
|
/// Print this error as a warning
|
|
#[inline(never)] #[cold] pub fn warn(self) -> Self
|
|
{
|
|
warn!("{}", self);
|
|
self
|
|
}
|
|
|
|
/// Print this error as info
|
|
#[inline(never)] #[cold] pub fn info(self) -> Self
|
|
{
|
|
info!("{}", self);
|
|
self
|
|
}
|
|
}
|
|
|
|
impl error::Error for Error{}
|
|
impl error::Error for HandleError{}
|
|
impl fmt::Display for Error
|
|
{
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
|
{
|
|
match self {
|
|
Self::Denied(sock, true) => write!(f, "denied connection (explicit): {}", sock),
|
|
Self::Denied(sock, _) => write!(f, "denied connection (implicit): {}", sock),
|
|
Self::TimeoutReached => write!(f, "timeout reached"),
|
|
Self::NoResponse => write!(f, "no handler for this request"),
|
|
_ => write!(f, "unknown error"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for HandleError
|
|
{
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
|
{
|
|
write!(f, "handle response had already been sent or timed out by the time we tried to access it")
|
|
}
|
|
}
|
|
|