@@ -12,6 +12,7 @@ use crate::handlers::Context;
1212use crate :: handlers:: docs_update:: docs_update;
1313use crate :: handlers:: pr_tracking:: get_assigned_prs;
1414use crate :: handlers:: project_goals:: { self , ping_project_goals_owners} ;
15+ use crate :: interactions:: ErrorComment ;
1516use crate :: utils:: pluralize;
1617use crate :: zulip:: api:: { MessageApiResponse , Recipient } ;
1718use crate :: zulip:: client:: ZulipClient ;
@@ -21,6 +22,7 @@ use crate::zulip::commands::{
2122use anyhow:: { Context as _, format_err} ;
2223use axum:: Json ;
2324use axum:: extract:: State ;
25+ use axum:: extract:: rejection:: JsonRejection ;
2426use axum:: response:: IntoResponse ;
2527use rust_team_data:: v1:: { TeamKind , TeamMember } ;
2628use std:: cmp:: Reverse ;
@@ -92,11 +94,24 @@ struct Response {
9294/// Top-level handler for Zulip webhooks.
9395///
9496/// Returns a JSON response or a 400 with an error message.
95- // TODO: log JsonRejection
9697pub async fn webhook (
9798 State ( ctx) : State < Arc < Context > > ,
98- Json ( req) : Json < Request > ,
99+ req : Result < Json < Request > , JsonRejection > ,
99100) -> axum:: response:: Response {
101+ let Json ( req) = match req {
102+ Ok ( req) => req,
103+ Err ( rejection) => {
104+ tracing:: error!( ?rejection) ;
105+ return Json ( Response {
106+ content : ErrorComment :: markdown (
107+ "unable to handle this Zulip request: invalid JSON input" ,
108+ )
109+ . expect ( "creating a error message without fail" ) ,
110+ } )
111+ . into_response ( ) ;
112+ }
113+ } ;
114+
100115 tracing:: info!( ?req) ;
101116 let response = process_zulip_request ( ctx, req) . await ;
102117 tracing:: info!( ?response) ;
@@ -111,9 +126,6 @@ pub async fn webhook(
111126 // We are mixing network errors and "logic" error (like clap errors)
112127 // so don't return a 500. Long term we should decouple those.
113128
114- // Log the full error
115- tracing:: error!( ?err) ;
116-
117129 // Reply with a 200 and reply only with outermost error
118130 Json ( Response {
119131 content : err. to_string ( ) ,
@@ -150,8 +162,6 @@ async fn process_zulip_request(ctx: Arc<Context>, req: Request) -> anyhow::Resul
150162 anyhow:: bail!( "Invalid authorization." ) ;
151163 }
152164
153- log:: trace!( "zulip hook: {req:?}" ) ;
154-
155165 // Zulip commands are only available to users in the team database
156166 let gh_id = match ctx. team . zulip_to_github_id ( req. message . sender_id ) . await {
157167 Ok ( Some ( gh_id) ) => gh_id,
0 commit comments