fix: return error if GetOperation call fails #1304
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes googleapis/nodejs-video-intelligence#523.
When a long running operation starts, we start polling for result by sending
GetOperation
calls. Apparently, if aGetOperation
call itself fails (e.g. with8 RESOURCE_EXHAUSTED
), this error is never handled properly, resulting in an unhandled rejection.The problem is in the following piece of code:
gax-nodejs/src/longRunningCalls/longrunning.ts
Lines 192 to 196 in b01bf8d
In the created promise, the
promisifyResponse
call handles the case whereGetOperation
returned success but the operation itself has failed, but the case whereGetOperation
itself fails is not handled. I'm adding error handling in this place by supplying the second parameter to.then()
and calling the provided callback if it's set, and rejecting the promise if not. In the real life use case, the callback is supplied:gax-nodejs/src/longRunningCalls/longrunning.ts
Lines 293 to 297 in b01bf8d
I added a unit test for this fix, and tested it locally with the real quota errors returned by Video Intelligence API.