@@ -83,7 +83,7 @@ export class StandardHandler<T extends Context> {
8383 return runWithSpan (
8484 { name : `${ request . method } ${ request . url . pathname } ` } ,
8585 async ( span ) => {
86- let step : 'decode_input' | ' call_procedure' | undefined
86+ let step : 'call_procedure' | undefined
8787
8888 try {
8989 return await intercept (
@@ -113,12 +113,22 @@ export class StandardHandler<T extends Context> {
113113 span ?. setAttribute ( 'rpc.system' , ORPC_NAME )
114114 span ?. setAttribute ( 'rpc.method' , match . path . join ( '.' ) )
115115
116- step = 'decode_input'
117- let input = await runWithSpan (
118- { name : 'decode_input' } ,
119- ( ) => this . codec . decode ( request , match . params , match . procedure ) ,
120- )
121- step = undefined
116+ let input : unknown
117+ try {
118+ input = await runWithSpan (
119+ { name : 'decode_input' } ,
120+ ( ) => this . codec . decode ( request , match . params , match . procedure ) ,
121+ )
122+ }
123+ catch ( e ) {
124+ // Convert here so interceptors (e.g. the rethrow filter) see the same error the client gets.
125+ throw e instanceof ORPCError
126+ ? e
127+ : new ORPCError ( 'BAD_REQUEST' , {
128+ message : `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.` ,
129+ cause : e ,
130+ } )
131+ }
122132
123133 if ( isAsyncIteratorObject ( input ) ) {
124134 input = asyncIteratorWithSpan (
@@ -161,12 +171,7 @@ export class StandardHandler<T extends Context> {
161171 setSpanError ( span , e )
162172 }
163173
164- const error = step === 'decode_input' && ! ( e instanceof ORPCError )
165- ? new ORPCError ( 'BAD_REQUEST' , {
166- message : `Malformed request. Ensure the request body is properly formatted and the 'Content-Type' header is set correctly.` ,
167- cause : e ,
168- } )
169- : toORPCError ( e )
174+ const error = toORPCError ( e )
170175
171176 const response = this . codec . encodeError ( error )
172177
0 commit comments