I have this dummy code
var Promise = require('bluebird')
function rej1(){
return new Promise.reject(new Error('rej1'));
}
function rej2() {
return new Promise.reject(new Error('rej2'));
}
function rej3() {
return new Promise.reject(new Error('rej3'));
}
Promise.all([rej1(),rej2(),rej3()] ).then(function(){
console.log('haha')
},function(e){
console.error(e);
})
In the rejectionHandler i see only the first rejection. Is it possible to view all three rejections?
Yes, it is possible to view all three rejections. Promise.all
rejects as soon as one promise rejects. Instead - use Promise.settle
:
Promise.settle([rej1(), rej2(), rej3()).then(function(results){
var rejections = results.filter(function(el){ return el.isRejected(); });
// access rejections here
rejections[0].reason(); // contains the first rejection reason
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With