Skip to content

Commit

Permalink
[SIEM] Fixes unhandled promise rejection warning in test case (elasti…
Browse files Browse the repository at this point in the history
…c#50834) (elastic#51034)

* fixes unhandled promise rejection when savedObject fails to find object with id

* comments as to why / how / where this try-catch is needed
  • Loading branch information
dhurley14 authored Nov 19, 2019
1 parent d0796bd commit 57083d4
Showing 1 changed file with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,24 @@ export const QueryBarTimeline = memo<QueryBarTimelineComponentProps>(
let isSubscribed = true;
async function setSavedQueryByServices() {
if (savedQueryId != null && savedQueryServices != null) {
const mySavedQuery = await savedQueryServices.getSavedQuery(savedQueryId);
if (isSubscribed) {
setSavedQuery({
...mySavedQuery,
attributes: {
...mySavedQuery.attributes,
filters: filters.filter(f => f.meta.controlledBy !== timelineFilterDropArea),
},
});
try {
// The getSavedQuery function will throw a promise rejection in
// src/legacy/core_plugins/data/public/search/search_bar/lib/saved_query_service.ts
// if the savedObjectsClient is undefined. This is happening in a test
// so I wrapped this in a try catch to keep the unhandled promise rejection
// warning from appearing in tests.
const mySavedQuery = await savedQueryServices.getSavedQuery(savedQueryId);
if (isSubscribed && mySavedQuery != null) {
setSavedQuery({
...mySavedQuery,
attributes: {
...mySavedQuery.attributes,
filters: filters.filter(f => f.meta.controlledBy !== timelineFilterDropArea),
},
});
}
} catch (exc) {
setSavedQuery(null);
}
} else if (isSubscribed) {
setSavedQuery(null);
Expand Down

0 comments on commit 57083d4

Please sign in to comment.