Skip to content

Commit

Permalink
Fix saved objects client _processBatchQueue function to handle errors (
Browse files Browse the repository at this point in the history
…elastic#26763) (elastic#26808)

* Fix saved objects client _processBatchQueue function to handle errors

* Fix error thrown in try/catch
  • Loading branch information
mikecote authored Dec 7, 2018
1 parent 4042475 commit 7f9cde7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/ui/public/saved_objects/__tests__/saved_objects_client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
4 changes: 4 additions & 0 deletions src/ui/public/saved_objects/saved_objects_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ export class SavedObjectsClient {

queueItem.resolve(foundObject);
});
}).catch((err) => {
queue.forEach((queueItem) => {
queueItem.reject(err);
});
});

}, BATCH_INTERVAL, { leading: false });
Expand Down

0 comments on commit 7f9cde7

Please sign in to comment.