@@ -138,7 +138,7 @@ export class StandardHandler<T extends Context> {
138138 async ( { context, prefix, request } ) => {
139139 const span = getTracer ( ) ?. getActiveSpan ( )
140140
141- let step : 'decode_input' | ' call_procedure' | undefined
141+ let step : 'call_procedure' | undefined
142142
143143 const matchedOrNot = await runWithSpan ( 'find_procedure' , ( ) =>
144144 this . codec . resolveProcedure ( request , { context, prefix } ) ,
@@ -172,10 +172,21 @@ export class StandardHandler<T extends Context> {
172172 { context, prefix, request, path, procedure, decodeInput } ,
173173
174174 async ( { context, prefix, request, path, procedure, decodeInput } ) => {
175- step = 'decode_input'
176- let input = await runWithSpan ( 'decode_input' , decodeInput )
177175 step = undefined
178176
177+ let input : unknown
178+ try {
179+ input = await runWithSpan ( 'decode_input' , decodeInput )
180+ } catch ( e ) {
181+ // Convert here so interceptors see the same error the client gets.
182+ throw e instanceof ORPCError
183+ ? e
184+ : new ORPCError ( 'BAD_REQUEST' , {
185+ message : `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.` ,
186+ cause : e ,
187+ } )
188+ }
189+
179190 if ( getTracer ( ) && isAsyncIteratorObject ( input ) ) {
180191 input = traceAsyncIterator ( 'consume_async_iterator_object_input' , input )
181192 } else if ( getTracer ( ) && input instanceof ReadableStream ) {
@@ -220,13 +231,7 @@ export class StandardHandler<T extends Context> {
220231 recordSpanError ( span , e )
221232 }
222233
223- const error =
224- step === 'decode_input' && ! ( e instanceof ORPCError )
225- ? new ORPCError ( 'BAD_REQUEST' , {
226- message : `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.` ,
227- cause : e ,
228- } )
229- : toORPCError ( e )
234+ const error = toORPCError ( e )
230235
231236 /**
232237 * The procedure client already reconciles what it rejects with,
0 commit comments