diff --git a/src/ui/public/courier/fetch/__tests__/call_client.js b/src/ui/public/courier/fetch/__tests__/call_client.js index 565af41f23ebfb..efb26e7ea25988 100644 --- a/src/ui/public/courier/fetch/__tests__/call_client.js +++ b/src/ui/public/courier/fetch/__tests__/call_client.js @@ -119,6 +119,35 @@ describe('callClient', () => { expect(results).to.eql([1]); }); }); + + it(`resolves the promise despite the request failing`, () => { + addSearchStrategy({ + id: 'fail', + isViable: indexPattern => { + return indexPattern.type === 'fail'; + }, + search: () => { + return { + searching: Promise.reject(new Error('Search failed')), + failedSearchRequests: [], + abort: () => {}, + }; + }, + }); + + const searchRequestFail = createSearchRequest('fail', { + source: { + getField: () => ({ type: 'fail' }), + }, + }); + + searchRequests = [ searchRequestFail ]; + const callingClient = callClient(searchRequests); + + return callingClient.then(results => { + expect(results).to.eql(undefined); + }); + }); }); describe('implementation', () => { diff --git a/src/ui/public/courier/fetch/call_client.js b/src/ui/public/courier/fetch/call_client.js index fd8266eb6e122a..d279b9deb343e4 100644 --- a/src/ui/public/courier/fetch/call_client.js +++ b/src/ui/public/courier/fetch/call_client.js @@ -183,17 +183,18 @@ export function CallClientProvider(Private, Promise, es) { } }); - // If there are any errors, notify the searchRequests of them. - defer.promise.catch((err) => { + // Return the promise which acts as our vehicle for providing search responses to the consumer. + // However, if there are any errors, notify the searchRequests of them *instead* of bubbling + // them up to the consumer. + return defer.promise.catch((err) => { + // By returning the return value of this catch() without rethrowing the error, we delegate + // error-handling to the searchRequest instead of the consumer. searchRequests.forEach((searchRequest, index) => { if (searchRequestsAndStatuses[index] !== ABORTED) { searchRequest.handleFailure(err); } }); }); - - // Return the promise which acts as our vehicle for providing search responses to the consumer. - return defer.promise; } return callClient;