@@ -12,6 +12,7 @@ use crate::handlers::Context;
12
12
use crate :: handlers:: docs_update:: docs_update;
13
13
use crate :: handlers:: pr_tracking:: get_assigned_prs;
14
14
use crate :: handlers:: project_goals:: { self , ping_project_goals_owners} ;
15
+ use crate :: interactions:: ErrorComment ;
15
16
use crate :: utils:: pluralize;
16
17
use crate :: zulip:: api:: { MessageApiResponse , Recipient } ;
17
18
use crate :: zulip:: client:: ZulipClient ;
@@ -21,6 +22,7 @@ use crate::zulip::commands::{
21
22
use anyhow:: { Context as _, format_err} ;
22
23
use axum:: Json ;
23
24
use axum:: extract:: State ;
25
+ use axum:: extract:: rejection:: JsonRejection ;
24
26
use axum:: response:: IntoResponse ;
25
27
use rust_team_data:: v1:: { TeamKind , TeamMember } ;
26
28
use std:: cmp:: Reverse ;
@@ -92,11 +94,24 @@ struct Response {
92
94
/// Top-level handler for Zulip webhooks.
93
95
///
94
96
/// Returns a JSON response or a 400 with an error message.
95
- // TODO: log JsonRejection
96
97
pub async fn webhook (
97
98
State ( ctx) : State < Arc < Context > > ,
98
- Json ( req) : Json < Request > ,
99
+ req : Result < Json < Request > , JsonRejection > ,
99
100
) -> 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
+
100
115
tracing:: info!( ?req) ;
101
116
let response = process_zulip_request ( ctx, req) . await ;
102
117
tracing:: info!( ?response) ;
@@ -111,9 +126,6 @@ pub async fn webhook(
111
126
// We are mixing network errors and "logic" error (like clap errors)
112
127
// so don't return a 500. Long term we should decouple those.
113
128
114
- // Log the full error
115
- tracing:: error!( ?err) ;
116
-
117
129
// Reply with a 200 and reply only with outermost error
118
130
Json ( Response {
119
131
content : err. to_string ( ) ,
@@ -150,8 +162,6 @@ async fn process_zulip_request(ctx: Arc<Context>, req: Request) -> anyhow::Resul
150
162
anyhow:: bail!( "Invalid authorization." ) ;
151
163
}
152
164
153
- log:: trace!( "zulip hook: {req:?}" ) ;
154
-
155
165
// Zulip commands are only available to users in the team database
156
166
let gh_id = match ctx. team . zulip_to_github_id ( req. message . sender_id ) . await {
157
167
Ok ( Some ( gh_id) ) => gh_id,
0 commit comments