Skip to content

Commit 63d9717

Browse files
committed
grpc-js: Prioritize HTTP status errors over message decoding errors
1 parent e9359ef commit 63d9717

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

packages/grpc-js/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@grpc/grpc-js",
3-
"version": "1.12.4",
3+
"version": "1.12.5",
44
"description": "gRPC Library for Node - pure JS implementation",
55
"homepage": "https://grpc.io/",
66
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",

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

+16-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,22 @@ export class Http2SubchannelCall implements SubchannelCall {
190190
try {
191191
messages = this.decoder.write(data);
192192
} catch (e) {
193-
this.cancelWithStatus(Status.RESOURCE_EXHAUSTED, (e as Error).message);
193+
/* Some servers send HTML error pages along with HTTP status codes.
194+
* When the client attempts to parse this as a length-delimited
195+
* message, the parsed message size is greater than the default limit,
196+
* resulting in a message decoding error. In that situation, the HTTP
197+
* error code information is more useful to the user than the
198+
* RESOURCE_EXHAUSTED error is, so we report that instead. Normally,
199+
* we delay processing the HTTP status until after the stream ends, to
200+
* prioritize reporting the gRPC status from trailers if it is present,
201+
* but when there is a message parsing error we end the stream early
202+
* before processing trailers. */
203+
if (this.httpStatusCode !== undefined && this.httpStatusCode !== 200) {
204+
const mappedStatus = mapHttpStatusCode(this.httpStatusCode);
205+
this.cancelWithStatus(mappedStatus.code, mappedStatus.details);
206+
} else {
207+
this.cancelWithStatus(Status.RESOURCE_EXHAUSTED, (e as Error).message);
208+
}
194209
return;
195210
}
196211

0 commit comments

Comments
 (0)