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

This commit is contained in:
James Gowdy 2018-07-31 14:08:43 +01:00 committed by GitHub
parent 430ad1592b
commit 149ff8ed17
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);