I'm using lodash _.forEach loop and inside _.forEach loop i'm using multiple promise and putting inside array promises. using sendEmailApi method I'm sending email to users, My requirement is if i get any error from I want to exit from outer _.forEach loop , dont want to process all promises. code below written but not working , it's processing the whole _.forEach loop if i get any error from in the middle of loop
_.forEach(result, function (value, index) {
_.forEach(value, function (value1, index1) {
if(!displayName)
displayName = value1.displayname;
productList += '"' + value1.productplannames + '",';
});
tempJsonStr = '{"email":"' + index + '","displayname":"' + displayName + '","productplannames":[' + _.trim(productList, ",") + ']}';
console.log("tempJsonStr",tempJsonStr);
productList ="";
displayName="";
promises.push(emailUtils.sendEmailApiProcess(JSON.parse(tempJsonStr),responsePayLoad,task,done).then(function () {
}).catch(err => {
console.log("errrrrrrrrr");
return false;
}))
});
Promise.all(promises).then(function () {
console.log("All done");
});