Fix saved objects client _processBatchQueue function to handle errors (#26763)

* Fix saved objects client _processBatchQueue function to handle errors

* Fix error thrown in try/catch
This commit is contained in:
Mike Côté 2018-12-07 09:01:17 -05:00 committed by GitHub
parent 5ed3233fdd
commit 44f976b42c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View file

@ -128,6 +128,21 @@ describe('SavedObjectsClient', () => {
await savedObjectsClient.get(doc.type, doc.id);
sinon.assert.calledOnce(kfetchStub);
});
test('handles HTTP call when it fails', async () => {
kfetchStub.withArgs({
method: 'POST',
pathname: `/api/saved_objects/_bulk_get`,
query: undefined,
body: sinon.match.any
}).rejects(new Error('Request failed'));
try {
await savedObjectsClient.get(doc.type, doc.id);
throw new Error('should have error');
} catch (e) {
expect(e.message).to.be('Request failed');
}
});
});
describe('#delete', () => {

View file

@ -215,6 +215,10 @@ export class SavedObjectsClient {
queueItem.resolve(foundObject);
});
}).catch((err) => {
queue.forEach((queueItem) => {
queueItem.reject(err);
});
});
}, BATCH_INTERVAL, { leading: false });