add test + json errors

This commit is contained in:
2026-05-31 21:30:17 +00:00
parent 227fcfaafb
commit 7e3b49ad76
3 changed files with 231 additions and 24 deletions
+37 -11
View File
@@ -15,6 +15,12 @@ pub enum AppError {
#[error("WebHook sig header is invalid")]
WebHookSigHeaderInvalidErr,
#[error("Missing required field: {0}")]
MissingField(String),
#[error("Wrong type for field: {0}")]
WrongFieldType(String),
#[error(transparent)]
Other(#[from] anyhow::Error),
}
@@ -22,19 +28,39 @@ pub enum AppError {
impl IntoResponse for AppError {
fn into_response(self) -> axum::response::Response {
match self {
AppError::MalformedJsonErr => (StatusCode::BAD_REQUEST, "Malformed Json"),
AppError::MalformedJsonErr => {
(StatusCode::BAD_REQUEST, "Malformed Json".to_string()).into_response()
}
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"),
"Json not contains mandatory fields".to_string(),
)
.into_response(),
AppError::WebHookSigHeaderNotFoundErr => (
StatusCode::BAD_REQUEST,
"WebHook sig header not found".to_string(),
)
.into_response(),
AppError::WebHookSigHeaderInvalidErr => (
StatusCode::UNAUTHORIZED,
"WebHook sig header is invalid".to_string(),
)
.into_response(),
AppError::MissingField(ref field) => (
StatusCode::BAD_REQUEST,
format!("Missing required field: {}", field),
)
.into_response(),
AppError::WrongFieldType(ref field) => (
StatusCode::BAD_REQUEST,
format!("Wrong type for field: {}", field),
)
.into_response(),
AppError::Other(_) => (
StatusCode::INTERNAL_SERVER_ERROR,
"Internal server error".to_string(),
)
.into_response(),
}
.into_response()
}
}