Merge pull request #2073 from murgatroid99/grpc-js_write_error_handling

grpc-js: Avoid surfacing errors without gRPC error codes
This commit is contained in:
Michael Lumish 2022-03-30 09:39:52 -07:00 committed by GitHub
commit 76d03e7f47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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;