Skip to content

Commit

Permalink
GrpcWebClientBase: handle falsy response
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed Apr 27, 2022
1 parent 49a9153 commit a317912
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions javascript/net/grpc/web/grpcwebclientbase.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class GrpcWebClientBase {
this.streamInterceptors_);
const stream = /** @type {!ClientReadableStream<?>} */ (invoker.call(
this, methodDescriptor.createRequest(requestMessage, metadata)));
GrpcWebClientBase.setCallback_(stream, callback, false);
GrpcWebClientBase.setCallback_(stream, callback);
return new ClientUnaryCallImpl(stream);
}

Expand All @@ -126,17 +126,17 @@ class GrpcWebClientBase {
stream, (error, response, status, metadata) => {
if (error) {
reject(error);
} else if (response) {
unaryMsg = response;
} else if (status) {
unaryStatus = status;
} else if (metadata) {
unaryMetadata = metadata;
} else if (status) {
unaryStatus = status;
} else {
resolve(request.getMethodDescriptor().createUnaryResponse(
unaryMsg, unaryMetadata, unaryStatus));
unaryMsg = response;
}
}, true);
}, () => {
resolve(request.getMethodDescriptor().createUnaryResponse(
unaryMsg, unaryMetadata, unaryStatus));
});
});
const invoker = GrpcWebClientBase.runInterceptors_(
initialInvoker, this.unaryInterceptors_);
Expand Down Expand Up @@ -224,9 +224,9 @@ class GrpcWebClientBase {
* @param {!ClientReadableStream<RESPONSE>} stream
* @param {function(?RpcError, ?RESPONSE, ?Status=, ?Object<string, string>=)|
* function(?RpcError,?RESPONSE)} callback
* @param {boolean} useUnaryResponse
* @param {?function()} triggerUnaryResponse
*/
static setCallback_(stream, callback, useUnaryResponse) {
static setCallback_(stream, callback, triggerUnaryResponse) {
let isResponseReceived = false;
let responseReceived = null;
let errorEmitted = false;
Expand Down Expand Up @@ -258,7 +258,7 @@ class GrpcWebClientBase {
}
});

if (useUnaryResponse) {
if (triggerUnaryResponse) {
stream.on('metadata', function(metadata) {
callback(null, null, null, metadata);
});
Expand All @@ -275,8 +275,8 @@ class GrpcWebClientBase {
callback(null, responseReceived);
}
}
if (useUnaryResponse) {
callback(null, null); // trigger unaryResponse
if (triggerUnaryResponse) {
triggerUnaryResponse();
}
});
}
Expand Down

0 comments on commit a317912

Please sign in to comment.