Skip to content

Commit

Permalink
fix: add addition check if the provided code is valid gRPC code
Browse files Browse the repository at this point in the history
  • Loading branch information
Algin Maduro committed Sep 1, 2020
1 parent 5e42be1 commit aaee068
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions packages/grpc-js/src/server-call.ts
Expand Up @@ -739,15 +739,24 @@ export class Http2ServerCallStream<
} else {
this.messagesToPush.push(deserialized);
}
} catch (err) {
} catch (error) {
// Ignore any remaining messages when errors occur.
this.bufferedMessages.length = 0;

if(!err.code){
err.code = Status.INTERNAL;
if (
!(
'code' in error &&
typeof error.code === 'number' &&
Number.isInteger(error.code) &&
error.code >= Status.OK &&
error.code <= Status.UNAUTHENTICATED
)
) {
// The error code is not a valid gRPC code so its being overwritten.
error.code = Status.INTERNAL;
}
readable.emit('error', err);

readable.emit('error', error);
}

this.isPushPending = false;
Expand Down

0 comments on commit aaee068

Please sign in to comment.