Skip iteration if can not parse using JSON parse

This commit is contained in:
Jesús Ángel González 2018-03-19 12:42:35 +01:00
parent 174a890b18
commit a1b8a01081

View File

@ -345,13 +345,19 @@ module.exports = (server, options) => {
}
});
if(data && data.hits && data.hits.hits){
const minimum = ["@timestamp", "full_log", "manager.name", "agent.id"];
let list = [];
if(data.hits.hits.length === 0) throw new Error('There is no index pattern');
for(const index of data.hits.hits){
let valid = JSON.parse(index._source['index-pattern'].fields).filter(item => minimum.includes(item.name));
for(const index of data.hits.hits){
let valid, parsed;
try{
parsed = JSON.parse(index._source['index-pattern'].fields)
} catch (error){
continue;
}
valid = parsed.filter(item => minimum.includes(item.name));
if(valid.length === 4){
list.push({
id: index._id.split('index-pattern:')[1],
@ -360,7 +366,6 @@ module.exports = (server, options) => {
}
}
return res({data: list});
}