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
  • Loading branch information
mikecote committed Dec 6, 2018
1 parent 5c1615d commit 0a336c7
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);
expect().throw('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 0a336c7

Please sign in to comment.