41 lines
1.2 KiB
Rust
41 lines
1.2 KiB
Rust
use axum::response::IntoResponse;
|
|
use reqwest::StatusCode;
|
|
|
|
#[derive(thiserror::Error, Debug)]
|
|
pub enum AppError {
|
|
#[error("Malformed Json")]
|
|
MalformedJsonErr,
|
|
|
|
#[error("Json not contains mandatory fields")]
|
|
BadJsonStructErr,
|
|
|
|
#[error("WebHook sig header not found")]
|
|
WebHookSigHeaderNotFoundErr,
|
|
|
|
#[error("WebHook sig header is invalid")]
|
|
WebHookSigHeaderInvalidErr,
|
|
|
|
#[error(transparent)]
|
|
Other(#[from] anyhow::Error),
|
|
}
|
|
|
|
impl IntoResponse for AppError {
|
|
fn into_response(self) -> axum::response::Response {
|
|
match self {
|
|
AppError::MalformedJsonErr => (StatusCode::BAD_REQUEST, "Malformed Json"),
|
|
AppError::BadJsonStructErr => (
|
|
StatusCode::BAD_REQUEST,
|
|
"Json not contains mandatory fields",
|
|
),
|
|
AppError::WebHookSigHeaderNotFoundErr => {
|
|
(StatusCode::BAD_REQUEST, "WebHook sig header not found")
|
|
}
|
|
AppError::WebHookSigHeaderInvalidErr => {
|
|
(StatusCode::BAD_REQUEST, "WebHook sig header is invalid")
|
|
}
|
|
AppError::Other(_) => (StatusCode::INTERNAL_SERVER_ERROR, "Internal server error"),
|
|
}
|
|
.into_response()
|
|
}
|
|
}
|