Sunday 24 February 2019

In a set of chained promises with catch, how to know which promise failed?

// simple promise var asyncAdd = (a,b) => { return new Promise((resolve, reject) => { setTimeout(() => { if(typeof a === 'number' && typeof b === 'number'){ resolve(a+b); } else { reject('Argument msut be number'); } }, 1500); }); }; // promise usage asyncAdd(3,5).then((res) => { //first promise console.log(res); return asyncAdd(res, 33); }).then((res) => { // second promise console.log(res); }).catch((err) => { console.log(err); // catch }); how to find out which promise fails? Reasons: I may return different error msgs depending upon what failed.What's the common way to do it?

Submitted February 24, 2019 at 12:55PM by sum__sleples

No comments:

Post a Comment