grpc-js: Avoid surfacing errors without gRPC error codes

This commit is contained in:
murgatroid99 2022-03-28 14:06:04 -07:00
parent a6f3df70ae
commit 052af317a3
1 changed files with 10 additions and 1 deletions

View File

@ -839,7 +839,16 @@ export class Http2CallStream implements Call {
message,
flags: context.flags,
};
const cb: WriteCallback = context.callback ?? (() => {});
const cb: WriteCallback = (error?: Error | null) => {
let code: Status = Status.UNAVAILABLE;
if ((error as NodeJS.ErrnoException)?.code === 'ERR_STREAM_WRITE_AFTER_END') {
code = Status.INTERNAL;
}
if (error) {
this.cancelWithStatus(code, `Write error: ${error.message}`);
}
context.callback?.();
};
this.isWriteFilterPending = true;
this.filterStack.sendMessage(Promise.resolve(writeObj)).then((message) => {
this.isWriteFilterPending = false;