1use std::{error, fmt};
2
3#[derive(Debug)]
4pub struct CgiError {
5 content: &'static str,
6 kind: CgiErrorKind
7}
8
9impl CgiError {
10 pub fn new(content: &'static str, kind: CgiErrorKind) -> Self {
11 Self {
12 content: content,
13 kind: kind
14 }
15 }
16
17 pub fn kind(&self) -> CgiErrorKind {
18 self.kind.clone()
19 }
20
21 pub fn to_str(self) -> &'static str {
22 self.content
23 }
24
25 pub fn bytes(&self) -> &'static [u8] {
26 self.content.as_bytes()
27 }
28}
29
30impl fmt::Display for CgiError {
31 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32 write!(f, "{}", self.content)
33 }
34}
35
36impl error::Error for CgiError {}
37
38#[derive(Clone, Debug)]
39pub enum CgiErrorKind {
40 ContentLengthNotFound,
41 EmptyContent,
42 InputBodyFail,
43 ParseError,
44 PathInfoNotFound,
45 RequestMethodNodFound,
46}