use std::{error, fmt};
#[derive(Debug)]
pub struct CgiError {
content: &'static str,
kind: CgiErrorKind
}
impl CgiError {
pub fn new(content: &'static str, kind: CgiErrorKind) -> Self {
Self {
content: content,
kind: kind
}
}
pub fn kind(&self) -> CgiErrorKind {
self.kind.clone()
}
pub fn to_str(self) -> &'static str {
self.content
}
pub fn bytes(&self) -> &'static [u8] {
self.content.as_bytes()
}
}
impl fmt::Display for CgiError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.content)
}
}
impl error::Error for CgiError {}
#[derive(Clone, Debug)]
pub enum CgiErrorKind {
ContentLengthNotFound,
EmptyContent,
InputBodyFail,
ParseError,
PathInfoNotFound,
RequestMethodNodFound,
}