gateway_common/error/
mod.rs

1use std::fmt::{self, Display, Formatter};
2
3pub type BoxError = Box<dyn std::error::Error + Send + Sync>;
4
5#[derive(Debug)]
6pub struct MessageError(String);
7
8unsafe impl Send for MessageError {}
9
10unsafe impl Sync for MessageError {}
11
12impl Display for MessageError {
13    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
14        write!(f, "MessageError : {}", self.0)
15    }
16}
17
18impl std::error::Error for MessageError {}
19
20impl From<String> for MessageError {
21    fn from(value: String) -> Self {
22        MessageError(value.to_owned())
23    }
24}
25
26impl MessageError {
27    pub fn boxed(self) -> BoxError {
28        Box::new(self)
29    }
30}
31
32#[derive(Debug)]
33pub enum HttpError {
34    NotFind,
35    Unauthorized,
36    Error(String),
37}
38
39impl From<HttpError> for u16 {
40    fn from(value: HttpError) -> Self {
41        match value {
42            HttpError::NotFind => 404,
43            HttpError::Unauthorized => 401,
44            HttpError::Error(_) => 500,
45        }
46    }
47}