use std::error::Error; use std::fmt; #[derive(Debug)] pub enum ErrorKind { BadRequest(String), Conflict(String), ForbiddenRequest(String), NotFound(String), UnprocessiableRequest(String), JsonError(String), Other, } impl Error for ErrorKind {} impl fmt::Display for ErrorKind { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { ErrorKind::BadRequest(message) => { write!(f, "Client error - please try again! {}", message) } ErrorKind::Conflict(message) => { write!(f, "Client error - task is already underway! {}", message) } ErrorKind::ForbiddenRequest(message) => write!( f, "Client error - unauthorized. Please try again! {}", message ), ErrorKind::NotFound(message) => write!(f, "Client error - not found! {}", message), ErrorKind::UnprocessiableRequest(message) => write!( f, "Client error - the request can't be processed. Please try again! {}", message ), ErrorKind::JsonError(message) => { write!(f, "Client error - can't parse command! {}", message) } ErrorKind::Other => write!(f, "Other error that I did not anticipate"), } } }