Skip to content

Commit 0d23103

Browse files
committed
Handle json rejection for zulip webhook endpoint
1 parent 1f38e6b commit 0d23103

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/zulip.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::zulip::commands::{
2121
use anyhow::{Context as _, format_err};
2222
use axum::Json;
2323
use axum::extract::State;
24+
use axum::extract::rejection::JsonRejection;
2425
use axum::response::IntoResponse;
2526
use rust_team_data::v1::{TeamKind, TeamMember};
2627
use std::cmp::Reverse;
@@ -92,11 +93,18 @@ struct Response {
9293
/// Top-level handler for Zulip webhooks.
9394
///
9495
/// Returns a JSON response or a 400 with an error message.
95-
// TODO: log JsonRejection
9696
pub async fn webhook(
9797
State(ctx): State<Arc<Context>>,
98-
Json(req): Json<Request>,
98+
req: Result<Json<Request>, JsonRejection>,
9999
) -> axum::response::Response {
100+
let Json(req) = match req {
101+
Ok(req) => req,
102+
Err(rejection) => {
103+
tracing::error!(?rejection);
104+
return rejection.into_response();
105+
}
106+
};
107+
100108
tracing::info!(?req);
101109
let response = process_zulip_request(ctx, req).await;
102110
tracing::info!(?response);

0 commit comments

Comments
 (0)