add gitea sig header check, add Json errors, begin AppState
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user