Skip to content

Commit 052af31

Browse files
committed
grpc-js: Avoid surfacing errors without gRPC error codes
1 parent a6f3df7 commit 052af31

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)