Skip to content

Commit

Permalink
Merge pull request #1557 from mad-it/master
Browse files Browse the repository at this point in the history
fix(grpc-js): preserve original error code when the handler of a readable stream throws an error
  • Loading branch information
murgatroid99 committed Sep 2, 2020
2 parents e0b19e5 + aaee068 commit 1178d55
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/grpc-js/src/server-call.ts
Expand Up @@ -739,12 +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;

err.code = Status.INTERNAL;
readable.emit('error', err);
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', error);
}

this.isPushPending = false;
Expand Down

0 comments on commit 1178d55

Please sign in to comment.