From 753ad6dd05667edcc3bc260e0763daf1a6aa0e92 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 29 Sep 2024 18:24:50 -0400 Subject: [PATCH] Handle errors in push events. --- src/webhook.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/webhook.rs b/src/webhook.rs index 2bf4065..32cfb70 100644 --- a/src/webhook.rs +++ b/src/webhook.rs @@ -42,21 +42,29 @@ pub(crate) async fn hook( debug!("REQ: {:?}", payload); match payload { HookRequest::Push(webhook_payload) => { - handle_push( + let push_result = handle_push( state.gitea, state.kubernetes_client, state.allowed_repos.borrow(), webhook_payload, ) - .await - .expect("Failed to handle push event."); - ( - StatusCode::OK, - Json(HookResponse { - ok: true, - message: None, - }), - ) + .await; + match push_result { + Ok(_) => ( + StatusCode::OK, + Json(HookResponse { + ok: true, + message: None, + }), + ), + Err(_) => ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(HookResponse { + ok: false, + message: Some(format!("Failed to handle push event.")), + }), + ), + } } HookRequest::Unrecognized(payload) => ( StatusCode::BAD_REQUEST,