var isError = false;
savedata.ingredients.split(',').reduce(function(p, ing) {
return p.then(function() {
return db.dog_ingredients.create({ content_name: ing, dogFoodId: dogId });
});
}, Promise.resolve()).catch(function(e) {
console.log(e);
isError = true; ///// I want to modify the value here
});
console.log(isError); // output will be false.
if(isError){
res.status(400).send('Error');
}else{
res.status(200).send('Good');
}
I believe the external variable did not update because the promise is executed asynchronously. I am unsure how to resolve this issue.