File tree 2 files changed +28
-1
lines changed
2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -390,6 +390,18 @@ test('start operation handler errors', async (t) => {
390
390
at ServiceRegistry.start (/Users/bergundy/temporal/nexus-sdk-typescript/src/operation.ts)`
391
391
) ;
392
392
}
393
+ {
394
+ const res = await fetch ( `http://localhost:${ httpPort } /nexus/endpoints/${ endpointId } /services/testService/op` , {
395
+ method : 'POST' ,
396
+ body : 'invalid' ,
397
+ headers : {
398
+ 'Content-Type' : 'application/json' ,
399
+ } ,
400
+ } ) ;
401
+ t . is ( res . status , 400 ) ;
402
+ const { message } = await res . json ( ) as { message : string } ;
403
+ t . is ( message , 'Failed to deserialize input: SyntaxError: Unexpected token \'i\', "invalid" is not valid JSON' ) ;
404
+ }
393
405
} ) ;
394
406
} ) ;
395
407
Original file line number Diff line number Diff line change @@ -124,7 +124,15 @@ export class NexusHandler {
124
124
options : nexus . StartOperationOptions
125
125
) : Promise < coresdk . nexus . INexusTaskCompletion > {
126
126
try {
127
- const decoded = await decodeOptionalSingle ( this . dataConverter . payloadCodecs , payload ) ;
127
+ let decoded : Payload | undefined | null ;
128
+ try {
129
+ decoded = await decodeOptionalSingle ( this . dataConverter . payloadCodecs , payload ) ;
130
+ } catch ( err ) {
131
+ throw new nexus . HandlerError ( {
132
+ type : 'BAD_REQUEST' ,
133
+ message : `Failed to decode payload: ${ err } ` ,
134
+ } ) ;
135
+ }
128
136
// Nexus headers have string values and Temporal Payloads have binary values. Instead of converting Payload
129
137
// instances into Content instances, we embed the Payload in the serializer and pretend we are deserializing an
130
138
// empty Content.
@@ -452,7 +460,14 @@ class PayloadSerializer implements nexus.Serializer {
452
460
if ( this . payload == null ) {
453
461
return undefined as T ;
454
462
}
463
+ try {
455
464
return this . payloadConverter . fromPayload ( this . payload ) ;
465
+ } catch ( err ) {
466
+ throw new nexus . HandlerError ( {
467
+ type : 'BAD_REQUEST' ,
468
+ message : `Failed to deserialize input: ${ err } ` ,
469
+ } ) ;
470
+ }
456
471
}
457
472
458
473
/** Not used in this path */
You can’t perform that action at this time.
0 commit comments