#![allow(unused)]
use crate::http::status_code::HttpStatusCode;
#[derive(Debug,Clone)]
pub enum WaterErrors <'a>{
Server(ServerError<'a>),
Http(HttpStatusCode<'a>)
}
impl<'a> From<WaterErrors<'a>> for Result<(), WaterErrors<'a>> {
fn from(error: WaterErrors<'a>) -> Self {
Err(error)
}
}
#[derive(Debug,Clone)]
pub struct ServerError<'a> {
code:u16,
msg:&'a str
}
impl <'a> ServerError<'a> {
pub const fn new(code:u16,msg:&'a str)->ServerError<'a>{
ServerError {
code,
msg
}
}
}
macro_rules! form_server_errors {
{
$($(#[$docs:meta])* $name:ident = $code:expr => $msg:expr;)*
} => {
impl <'a> ServerError<'a> {
$(
$(#[$docs])*
pub const $name:ServerError<'static> = ServerError::new($code,$msg);
)*
}
};
}
form_server_errors!{
FLUSH_DATA_TOSTREAM_ERROR = 39 => "could not flush data to stream";
HANDLING_INCOMING_BODY_ERROR = 40 => "could not handle incoming body";
MULTIPARTFORMDATA_ERROR = 41 => "could not parse multipart form data";
WRITING_TO_STREAM_ERROR = 42 => "encounter error while writing to the stream";
}