Skip to content

Commit

Permalink
Fix regression in CallClient, which caused request errors like timeou…
Browse files Browse the repository at this point in the history
…ts to result in fatal errors. (#22558) (#22567)
  • Loading branch information
cjcenizal authored Aug 31, 2018
1 parent f166525 commit bfab464
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
29 changes: 29 additions & 0 deletions src/ui/public/courier/fetch/__tests__/call_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
11 changes: 6 additions & 5 deletions src/ui/public/courier/fetch/call_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit bfab464

Please sign in to comment.