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 for RequestError { fn from(e: std::io::Error) -> RequestError { RequestError::StreamIOError(e) } } impl From for RequestError { fn from(_e: Utf8Error) -> RequestError { RequestError::InvalidUtf8 } } // impl From 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"), } } }