mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 13:06:50 +00:00
30 lines
712 B
Rust
30 lines
712 B
Rust
|
|
use axum::http::StatusCode;
|
||
|
|
use std::fmt;
|
||
|
|
|
||
|
|
#[derive(Debug)]
|
||
|
|
pub struct PKError {
|
||
|
|
pub response_code: StatusCode,
|
||
|
|
pub json_code: i32,
|
||
|
|
pub message: &'static str,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl fmt::Display for PKError {
|
||
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||
|
|
write!(f, "{:?}", self)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
impl std::error::Error for PKError {}
|
||
|
|
|
||
|
|
macro_rules! define_error {
|
||
|
|
( $name:ident, $response_code:expr, $json_code:expr, $message:expr ) => {
|
||
|
|
const $name: PKError = PKError {
|
||
|
|
response_code: $response_code,
|
||
|
|
json_code: $json_code,
|
||
|
|
message: $message,
|
||
|
|
};
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
define_error! { GENERIC_BAD_REQUEST, StatusCode::BAD_REQUEST, 0, "400: Bad Request" }
|