[Fleet] Handle dashboard not found in datastream API (#98622) (#98654)

Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
This commit is contained in:
Kibana Machine 2021-04-28 14:35:02 -04:00 committed by GitHub
parent 8e759783e7
commit 6ea81a35fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -91,7 +91,7 @@ export const getListHandler: RequestHandler = async (context, request, response)
allDashboards[pkgSavedObject.id] = dashboards;
return allDashboards;
}, {});
const allDashboardSavedObjects = await context.core.savedObjects.client.bulkGet<{
const allDashboardSavedObjectsResponse = await context.core.savedObjects.client.bulkGet<{
title?: string;
}>(
Object.values(dashboardIdsByPackageName).reduce<SavedObjectsBulkGetObject[]>(
@ -107,8 +107,19 @@ export const getListHandler: RequestHandler = async (context, request, response)
[]
)
);
// Ignore dashboards not found
const allDashboardSavedObjects = allDashboardSavedObjectsResponse.saved_objects.filter((so) => {
if (so.error) {
if (so.error.statusCode === 404) {
return false;
}
throw so.error;
}
return true;
});
const allDashboardSavedObjectsById = keyBy(
allDashboardSavedObjects.saved_objects,
allDashboardSavedObjects,
(dashboardSavedObject) => dashboardSavedObject.id
);