mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Duplicate search strategy errors to correspond to the number of original requests. This fixes a bug in which more than one search request error would result in a fatal error. (#24952)
This commit is contained in:
parent
4c0a5e5a67
commit
0ec2950800
2 changed files with 19 additions and 4 deletions
|
@ -136,16 +136,25 @@ describe('callClient', () => {
|
|||
});
|
||||
|
||||
it(`still bubbles up the failure`, () => {
|
||||
const searchRequestFail = createSearchRequest('fail', {
|
||||
const searchRequestFail1 = createSearchRequest('fail1', {
|
||||
source: {
|
||||
getField: () => ({ type: 'fail' }),
|
||||
},
|
||||
});
|
||||
|
||||
searchRequests = [ searchRequestFail ];
|
||||
const searchRequestFail2 = createSearchRequest('fail2', {
|
||||
source: {
|
||||
getField: () => ({ type: 'fail' }),
|
||||
},
|
||||
});
|
||||
|
||||
searchRequests = [ searchRequestFail1, searchRequestFail2 ];
|
||||
|
||||
return callClient(searchRequests).then(results => {
|
||||
expect(results).to.eql([{ error: new Error('Search failed') }]);
|
||||
expect(results).to.eql([
|
||||
{ error: new Error('Search failed') },
|
||||
{ error: new Error('Search failed') },
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -152,6 +152,7 @@ export function CallClientProvider(Private, Promise, es, config) {
|
|||
abortableSearches.push({
|
||||
searching,
|
||||
abort,
|
||||
requestsCount: searchRequests.length,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -161,7 +162,12 @@ export function CallClientProvider(Private, Promise, es, config) {
|
|||
return;
|
||||
}
|
||||
|
||||
const segregatedResponses = await Promise.all(abortableSearches.map(({ searching }) => searching.catch((e) => [{ error: e }])));
|
||||
const segregatedResponses = await Promise.all(abortableSearches.map(async ({ searching, requestsCount }) => {
|
||||
return searching.catch((e) => {
|
||||
// Duplicate errors so that they correspond to the original requests.
|
||||
return new Array(requestsCount).fill({ error: e });
|
||||
});
|
||||
}));
|
||||
|
||||
// Assigning searchRequests to strategies means that the responses come back in a different
|
||||
// order than the original searchRequests. So we'll put them back in order so that we can
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue