use serde::Serialize; /// HTTP request error /// /// @author Pierre Hubert #[derive(Serialize)] pub struct InnerHTTPError { pub code: u16, pub message: String, } #[derive(Serialize)] pub struct HttpError { pub error: InnerHTTPError } impl HttpError { /// Generate a 404 error pub fn not_found(message: &str) -> HttpError { HttpError { error: InnerHTTPError { code: 404, message: message.to_string(), } } } /// Generate a 500 error pub fn internal_error(message: &str) -> HttpError { HttpError { error: InnerHTTPError { code: 500, message: message.to_string(), } } } /// Generate a 401 error pub fn bad_request(message: &str) -> HttpError { HttpError { error: InnerHTTPError { code: 401, message: message.to_string(), } } } }