add check for action and bot_name

This commit is contained in:
2026-06-02 18:42:59 +00:00
parent 0a22be252c
commit 14751f8db1
4 changed files with 126 additions and 39 deletions
+15 -7
View File
@@ -4,7 +4,7 @@ use reqwest::StatusCode;
#[derive(thiserror::Error, Debug)]
pub enum AppError {
#[error("Unauthorized user id")]
UnauthorizedUserIdErr,
UnauthorizedUserErr,
#[error("Unknow gitea event")]
UnknownEventErr,
@@ -12,15 +12,18 @@ pub enum AppError {
#[error("Malformed Json")]
MalformedJsonErr,
#[error(transparent)]
BadJsonStructErr(#[from] serde_json::Error),
#[error("WebHook header not found")]
WebHookMissingHeaderErr(String),
#[error("WebHook sig header is invalid")]
WebHookSigHeaderInvalidErr,
#[error("WebHook have bad action")]
InvalidActionErr,
#[error(transparent)]
BadJsonStructErr(#[from] serde_json::Error),
#[error(transparent)]
Other(#[from] anyhow::Error),
}
@@ -28,12 +31,17 @@ pub enum AppError {
impl IntoResponse for AppError {
fn into_response(self) -> axum::response::Response {
match self {
AppError::InvalidActionErr => (
StatusCode::UNPROCESSABLE_ENTITY,
"WebHook have bad action".to_string(),
),
AppError::UnknownEventErr => {
(StatusCode::BAD_REQUEST, "Unknow gitea event".to_string())
}
AppError::UnauthorizedUserIdErr => {
(StatusCode::BAD_REQUEST, "Unauthorized user id".to_string())
}
AppError::UnauthorizedUserErr => (
StatusCode::UNAUTHORIZED,
"Unauthorized user name".to_string(),
),
AppError::MalformedJsonErr => (StatusCode::BAD_REQUEST, "Malformed Json".to_string()),
AppError::BadJsonStructErr(err) => (
StatusCode::BAD_REQUEST,