Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delegate surfacing of Courier errors to the consumer #21056

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions src/ui/public/courier/fetch/__tests__/call_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,23 @@ describe('callClient', () => {
});
});

describe('errors', () => {
it(`cause searchRequest.handleFailure() to be called with the ES error that's thrown`, async () => {
esShouldError = true;
const searchRequest = createSearchRequest(1);

const handleFailureSpy = sinon.spy();
searchRequest.handleFailure = handleFailureSpy;

searchRequests = [ searchRequest ];
try {
await callClient(searchRequests);
} catch(e) {
sinon.assert.calledWith(handleFailureSpy, 'fake es error');
}
});
});

describe('implementation', () => {
it('calls es.msearch() once, regardless of number of searchRequests', () => {
expect(fakeSearch.callCount).to.be(0);
Expand All @@ -141,21 +158,6 @@ describe('callClient', () => {
await callClient(searchRequests);
expect(whenAbortedSpy.callCount).to.be(1);
});

it(`calls searchRequest.handleFailure() with the ES error that's thrown`, async () => {
esShouldError = true;
const searchRequest = createSearchRequest(1);

const handleFailureSpy = sinon.spy();
searchRequest.handleFailure = handleFailureSpy;

searchRequests = [ searchRequest ];
try {
await callClient(searchRequests);
} catch(e) {
sinon.assert.calledWith(handleFailureSpy, 'fake es error');
}
});
});

describe('aborting at different points in the request lifecycle:', () => {
Expand Down
7 changes: 4 additions & 3 deletions src/ui/public/courier/fetch/call_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export function CallClientProvider(Private, Promise, es) {
// order than the original searchRequests. So we'll put them back in order so that we can
// use the order to associate each response with the original request.
const responsesInOriginalRequestOrder = new Array(searchRequestsAndStatuses.length);

segregatedResponses.forEach((responses, strategyIndex) => {
responses.forEach((response, responseIndex) => {
const searchRequest = searchStrategiesWithRequests[strategyIndex].searchRequests[responseIndex];
Expand All @@ -185,9 +186,9 @@ export function CallClientProvider(Private, Promise, es) {

// If there are any errors, notify the searchRequests of them.
defer.promise.catch((err) => {
searchRequests.forEach((searchRequest, index) => {
if (searchRequestsAndStatuses[index] !== ABORTED) {
searchRequest.handleFailure(err);
searchRequestsAndStatuses.forEach((searchRequestOrStatus) => {
if (searchRequestOrStatus !== ABORTED) {
searchRequestOrStatus.handleFailure(err);
}
});
});
Expand Down
11 changes: 9 additions & 2 deletions src/ui/public/courier/fetch/fetch_now.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ export function FetchNowProvider(Private, Promise) {

return searchRequest.retry();
}))
.catch(error => fatalError(error, 'Courier fetch'));
.catch(error => {
// If any errors occur after the search requests have resolved, then we kill Kibana.
fatalError(error, 'Courier fetch');
});
}

function fetchSearchResults(searchRequests) {
Expand All @@ -70,7 +73,11 @@ export function FetchNowProvider(Private, Promise) {
return startRequests(searchRequests)
.then(function () {
replaceAbortedRequests();
return callClient(searchRequests);
return callClient(searchRequests)
.catch(() => {
// Silently swallow errors that result from search requests so the consumer can surface
// them as notifications instead of courier forcing fatal errors.
});
})
.then(function (responses) {
replaceAbortedRequests();
Expand Down