Skip to content

Commit

Permalink
Emit status event on empty stream response
Browse files Browse the repository at this point in the history
  • Loading branch information
shaxbee authored and stanley-cheung committed Jan 8, 2019
1 parent f181d1e commit bca6308
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions javascript/net/grpc/web/grpcwebclientreadablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ const GrpcWebClientReadableStream = function(genericTransportInterface) {
if (!contentType) return;
contentType = contentType.toLowerCase();

var grpcStatusCode = self.xhr_.getStreamingResponseHeader(GRPC_STATUS);
var grpcStatusMessage = self.xhr_.getStreamingResponseHeader(GRPC_STATUS_MESSAGE);
if (grpcStatusCode && self.onStatusCallback_) {
self.onStatusCallback_({
code: Number(grpcStatusCode),
details: grpcStatusMessage,
metadata: undefined,
});
}

if (googString.startsWith(contentType, 'application/grpc-web-text')) {
var responseText = self.xhr_.getResponseText();
var newPos = responseText.length - responseText.length % 4;
Expand Down Expand Up @@ -155,8 +165,8 @@ const GrpcWebClientReadableStream = function(genericTransportInterface) {
messages[i][FrameType.TRAILER][pos]);
}
var trailers = self.parseHttp1Headers_(trailerString);
var grpcStatusCode = StatusCode.OK;
var grpcStatusMessage = "";
grpcStatusCode = StatusCode.OK;
grpcStatusMessage = "";
if (GRPC_STATUS in trailers) {
grpcStatusCode = trailers[GRPC_STATUS];
}
Expand Down

0 comments on commit bca6308

Please sign in to comment.