baxe/
types.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use axum::http::StatusCode;
use axum::response::IntoResponse;
use axum::response::Response;
use axum::Json;
use serde::Serialize;

#[derive(Debug, Serialize)]
pub struct BaxeError {
    #[serde(skip)]
    pub status_code: StatusCode,
    pub message: String,
    pub code: u16,
    pub error_tag: String,
}

impl std::fmt::Display for BaxeError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.message)
    }
}

impl std::error::Error for BaxeError {}

impl IntoResponse for BaxeError {
    fn into_response(self) -> Response {
        (self.status_code, Json(self)).into_response()
    }
}