Skip to content

Commit 76d03e7

Browse files
authored
Merge pull request #2073 from murgatroid99/grpc-js_write_error_handling
grpc-js: Avoid surfacing errors without gRPC error codes
2 parents a6f3df7 + 052af31 commit 76d03e7

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/grpc-js/src/call-stream.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,16 @@ export class Http2CallStream implements Call {
839839
message,
840840
flags: context.flags,
841841
};
842-
const cb: WriteCallback = context.callback ?? (() => {});
842+
const cb: WriteCallback = (error?: Error | null) => {
843+
let code: Status = Status.UNAVAILABLE;
844+
if ((error as NodeJS.ErrnoException)?.code === 'ERR_STREAM_WRITE_AFTER_END') {
845+
code = Status.INTERNAL;
846+
}
847+
if (error) {
848+
this.cancelWithStatus(code, `Write error: ${error.message}`);
849+
}
850+
context.callback?.();
851+
};
843852
this.isWriteFilterPending = true;
844853
this.filterStack.sendMessage(Promise.resolve(writeObj)).then((message) => {
845854
this.isWriteFilterPending = false;

0 commit comments

Comments
 (0)