[ML] Fixing crash in fields service when user has no index permission (#21469) (#21474)

This commit is contained in:
James Gowdy 2018-07-31 15:48:35 +01:00 committed by GitHub
parent 37eec629a1
commit 5494e04870
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -69,11 +69,15 @@ export function fieldsServiceProvider(callWithRequest) {
})
.then((resp) => {
const aggregations = resp.aggregations;
const results = fieldNames.reduce((obj, field) => {
obj[field] = (aggregations[field] || { value: 0 }).value;
return obj;
}, {});
resolve(results);
if (aggregations !== undefined) {
const results = fieldNames.reduce((obj, field) => {
obj[field] = (aggregations[field] || { value: 0 }).value;
return obj;
}, {});
resolve(results);
} else {
resolve({});
}
})
.catch((resp) => {
reject(resp);