[SIEM] Fixes unhandled promise rejection warning in test case (#50834) (#51034)

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

* comments as to why / how / where this try-catch is needed
This commit is contained in:
Devin W. Hurley 2019-11-19 11:00:06 -05:00 committed by GitHub
parent d0796bd5f5
commit 57083d4be1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);