Skip to content

Commit

Permalink
Fix error callback
Browse files Browse the repository at this point in the history
  • Loading branch information
stanley-cheung committed Oct 16, 2019
1 parent c284b15 commit ab6ff71
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions javascript/net/grpc/web/streambodyclientreadablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,27 @@ const StreamBodyClientReadableStream = function(genericTransportInterface) {
this.xhrNodeReadableStream_.on('error', function() {
if (!self.onErrorCallback_) return;
var lastErrorCode = self.xhr_.getLastErrorCode();
if (lastErrorCode == ErrorCode.NO_ERROR) return;

var grpcStatusCode;
switch (lastErrorCode) {
case ErrorCode.NO_ERROR:
grpcStatusCode = StatusCode.UNKNOWN;
break;
case ErrorCode.ABORT:
grpcStatusCode = StatusCode.ABORTED;
break;
case ErrorCode.TIMEOUT:
grpcStatusCode = StatusCode.DEADLINE_EXCEEDED;
break;
case ErrorCode.HTTP_ERROR:
grpcStatusCode = StatusCode.fromHttpStatus(self.xhr_.getStatus());
break;
default:
grpcStatusCode = StatusCode.UNAVAILABLE;
}

self.onErrorCallback_({
code: StatusCode.UNAVAILABLE,
code: grpcStatusCode,
message: ErrorCode.getDebugMessage(lastErrorCode)
});
});
Expand Down

0 comments on commit ab6ff71

Please sign in to comment.