Skip to content
This repository was archived by the owner on Nov 18, 2025. It is now read-only.

Commit 1978197

Browse files
fix: do not throw error on empty LRO response (#1087)
Inspired by https://github.com/googleapis/nodejs-contact-center-insights/pull/34/files#r690783654. Some APIs end LRO without setting either result or error (but set `done: true`), that condition was previously considered an error but looks like it's OK to just return an empty response object in this case.
1 parent 6892cdd commit 1978197

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

src/longRunningCalls/longrunning.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,11 @@ export class Operation extends EventEmitter {
311311
}
312312
// special case: some APIs fail to set either result or error
313313
// but set done = true (e.g. speech with silent file).
314-
// Don't hang forever in this case.
314+
// Some APIs just use this for the normal completion
315+
// (e.g. nodejs-contact-center-insights), so let's just return
316+
// an empty response in this case.
315317
if (rawResponse!.done) {
316-
const error = new GoogleError(
317-
'Long running operation has finished but there was no result'
318-
);
319-
error.code = Status.UNKNOWN;
320-
setImmediate(emit, 'error', error);
318+
setImmediate(emit, 'complete', {}, metadata, rawResponse);
321319
return;
322320
}
323321
setTimeout(() => {

test/unit/longrunning.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -487,16 +487,16 @@ describe('longrunning', () => {
487487
apiCall({})
488488
.then(responses => {
489489
const operation = responses[0] as longrunning.Operation;
490-
const promise = operation.promise();
490+
const promise = operation.promise() as Promise<[{}, {}, {}]>;
491491
return promise;
492492
})
493-
.then(() => {
494-
done(new Error('Should not get here.'));
495-
})
496-
.catch(error => {
497-
assert(error instanceof Error);
493+
.then(([response, metadata, rawResponse]) => {
494+
assert.deepStrictEqual(response, {});
495+
assert.strictEqual(metadata, METADATA_VAL);
496+
assert.deepStrictEqual(rawResponse, BAD_OP);
498497
done();
499-
});
498+
})
499+
.catch(done);
500500
});
501501
});
502502

0 commit comments

Comments
 (0)