Skip to content

Commit d637251

Browse files
committed
Add more error logging for GitHub webhooks handling
1 parent 17a5801 commit d637251

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/github/webhook.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,11 @@ pub async fn webhook(
126126
) -> axum::response::Response {
127127
// Extract X-GitHub-Event header
128128
let Some(ev) = headers.get("X-GitHub-Event") else {
129+
tracing::error!("X-GitHub-Event header must be set");
129130
return (StatusCode::BAD_REQUEST, "X-GitHub-Event header must be set").into_response();
130131
};
131132
let Ok(ev) = ev.to_str() else {
133+
tracing::error!("X-GitHub-Event header must be UTF-8 encoded");
132134
return (
133135
StatusCode::BAD_REQUEST,
134136
"X-GitHub-Event header must be UTF-8 encoded",
@@ -141,13 +143,15 @@ pub async fn webhook(
141143

142144
// Extract X-Hub-Signature-256 header
143145
let Some(sig) = headers.get("X-Hub-Signature-256") else {
146+
tracing::error!("X-Hub-Signature-256 header must be set");
144147
return (
145148
StatusCode::BAD_REQUEST,
146149
"X-Hub-Signature-256 header must be set",
147150
)
148151
.into_response();
149152
};
150153
let Ok(signature) = sig.to_str() else {
154+
tracing::error!("X-Hub-Signature-256 header must be UTF-8 encoded");
151155
return (
152156
StatusCode::BAD_REQUEST,
153157
"X-Hub-Signature-256 header must be UTF-8 encoded",
@@ -158,19 +162,21 @@ pub async fn webhook(
158162
debug!("signature={signature}");
159163

160164
// Check signature on body
161-
if let Err(_) = check_payload_signed(&signature, &body) {
165+
if let Err(err) = check_payload_signed(&signature, &body) {
166+
tracing::error!("check_payload_signed: {}", err);
162167
return (StatusCode::FORBIDDEN, "Wrong signature").into_response();
163168
}
164169

165170
let Ok(payload) = str::from_utf8(&body) else {
171+
tracing::error!("payload not utf-8");
166172
return (StatusCode::BAD_REQUEST, "Payload must be UTF-8").into_response();
167173
};
168174

169175
match process_payload(event, payload, &ctx).await {
170176
Ok(true) => ("processed request",).into_response(),
171177
Ok(false) => ("ignored request",).into_response(),
172178
Err(err) => {
173-
tracing::error!("request failed: {:?}", err);
179+
tracing::error!("failed to process payload: {:?}", err);
174180
let body = format!("request failed: {:?}", err);
175181
(StatusCode::INTERNAL_SERVER_ERROR, body).into_response()
176182
}

0 commit comments

Comments
 (0)