use std::fmt::{Display, Formatter}; use std::convert::From; use std::str::Utf8Error; // error when attempting to tell a request handler whether to release or deny crednetials pub enum SendResponseError { NotFound, // no request with the given id Abandoned, // request has already been closed by client } impl Display for SendResponseError { fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> { use SendResponseError::*; match self { NotFound => write!(f, "The specified command was not found."), Abandoned => write!(f, "The specified request was closed by the client."), } } } // 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 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"), } } }