blockless_sdk/
error.rs

1#[derive(Debug)]
2pub enum HttpErrorKind {
3    InvalidDriver,
4    InvalidHandle,
5    MemoryAccessError,
6    BufferTooSmall,
7    HeaderNotFound,
8    Utf8Error,
9    DestinationNotAllowed,
10    InvalidMethod,
11    InvalidEncoding,
12    InvalidUrl,
13    RequestError,
14    RuntimeError,
15    TooManySessions,
16    PermissionDeny,
17}
18
19impl std::error::Error for HttpErrorKind {}
20
21impl std::fmt::Display for HttpErrorKind {
22    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23        match *self {
24            Self::InvalidDriver => write!(f, "Invalid Driver"),
25            Self::InvalidHandle => write!(f, "Invalid Error"),
26            Self::MemoryAccessError => write!(f, "Memoery Access Error"),
27            Self::BufferTooSmall => write!(f, "Buffer too small"),
28            Self::HeaderNotFound => write!(f, "Header not found"),
29            Self::Utf8Error => write!(f, "Utf8 error"),
30            Self::DestinationNotAllowed => write!(f, "Destination not allowed"),
31            Self::InvalidMethod => write!(f, "Invalid method"),
32            Self::InvalidEncoding => write!(f, "Invalid encoding"),
33            Self::InvalidUrl => write!(f, "Invalid url"),
34            Self::RequestError => write!(f, "Request url"),
35            Self::RuntimeError => write!(f, "Runtime error"),
36            Self::TooManySessions => write!(f, "Too many sessions"),
37            Self::PermissionDeny => write!(f, "Permision deny."),
38        }
39    }
40}
41
42impl From<u32> for HttpErrorKind {
43    fn from(i: u32) -> HttpErrorKind {
44        match i {
45            1 => HttpErrorKind::InvalidHandle,
46            2 => HttpErrorKind::MemoryAccessError,
47            3 => HttpErrorKind::BufferTooSmall,
48            4 => HttpErrorKind::HeaderNotFound,
49            5 => HttpErrorKind::Utf8Error,
50            6 => HttpErrorKind::DestinationNotAllowed,
51            7 => HttpErrorKind::InvalidMethod,
52            8 => HttpErrorKind::InvalidEncoding,
53            9 => HttpErrorKind::InvalidUrl,
54            10 => HttpErrorKind::RequestError,
55            11 => HttpErrorKind::RuntimeError,
56            12 => HttpErrorKind::TooManySessions,
57            13 => HttpErrorKind::PermissionDeny,
58            _ => HttpErrorKind::RuntimeError,
59        }
60    }
61}
62
63#[derive(Debug)]
64pub enum SocketErrorKind {
65    ConnectRefused,
66    ParameterError,
67    ConnectionReset,
68    AddressInUse,
69}
70
71impl std::fmt::Display for SocketErrorKind {
72    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
73        match *self {
74            SocketErrorKind::ConnectRefused => write!(f, "Connect Refused."),
75            SocketErrorKind::ParameterError => write!(f, "Parameter Error."),
76            SocketErrorKind::ConnectionReset => write!(f, "Connection  Reset."),
77            SocketErrorKind::AddressInUse => write!(f, "Address In Use."),
78        }
79    }
80}
81
82impl std::error::Error for SocketErrorKind {}
83
84#[derive(Debug)]
85pub enum CGIErrorKind {
86    ListError,
87    EncodingError,
88    JsonDecodingError,
89    ExecError,
90    ReadError,
91    NoCommandError,
92}
93
94impl std::fmt::Display for CGIErrorKind {
95    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
96        match *self {
97            CGIErrorKind::ListError => write!(f, "CGI List Error."),
98            CGIErrorKind::EncodingError => write!(f, "CGI Encoding Error."),
99            CGIErrorKind::JsonDecodingError => write!(f, "Json decoding Error."),
100            CGIErrorKind::ExecError => write!(f, "CGI Exec Error."),
101            CGIErrorKind::ReadError => write!(f, "Read Error."),
102            CGIErrorKind::NoCommandError => write!(f, "No CGI Command Error."),
103        }
104    }
105}
106
107impl std::error::Error for CGIErrorKind {}