42 lines
1.2 KiB
Rust
42 lines
1.2 KiB
Rust
|
use std::fmt::{Display, Formatter};
|
||
|
use std::convert::From;
|
||
|
use std::str::Utf8Error;
|
||
|
|
||
|
// use tokio::sync::oneshot::error::RecvError;
|
||
|
|
||
|
|
||
|
// Represents errors encountered while handling an HTTP request
|
||
|
pub enum RequestError {
|
||
|
StreamIOError(std::io::Error),
|
||
|
InvalidUtf8,
|
||
|
MalformedHttpRequest,
|
||
|
RequestTooLarge,
|
||
|
}
|
||
|
|
||
|
impl From<tokio::io::Error> for RequestError {
|
||
|
fn from(e: std::io::Error) -> RequestError {
|
||
|
RequestError::StreamIOError(e)
|
||
|
}
|
||
|
}
|
||
|
impl From<Utf8Error> for RequestError {
|
||
|
fn from(_e: Utf8Error) -> RequestError {
|
||
|
RequestError::InvalidUtf8
|
||
|
}
|
||
|
}
|
||
|
// impl From<RecvError> for RequestError {
|
||
|
// fn from (_e: RecvError) -> RequestError {
|
||
|
// RequestError::
|
||
|
// }
|
||
|
// }
|
||
|
|
||
|
impl Display for RequestError {
|
||
|
fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> {
|
||
|
use RequestError::*;
|
||
|
match self {
|
||
|
StreamIOError(e) => write!(f, "Stream IO error: {e}"),
|
||
|
InvalidUtf8 => write!(f, "Could not decode UTF-8 from bytestream"),
|
||
|
MalformedHttpRequest => write!(f, "Maformed HTTP request"),
|
||
|
RequestTooLarge => write!(f, "HTTP request too large"),
|
||
|
}
|
||
|
}
|
||
|
}
|