I have this array of Promises like:
let promisesArray = [
service1.load('blabla'),
service2.load(), // throws an errors
];
and I want to execute them all and catch their errors like this
Promise.all(promisesArray)
.then(() => doStuffs())
.catch((err) => handleError(err));
that's working fine but I now want to that in the then() of another promise:
baseService()
.then(() => Promise.all([
service1.load('blabla'),
service2.load(), // throw an errors
]))
.catch((err) => handleError(err));
this one's works also fine as long as I write the array directly in Promise.all(), but if I want to use promiseArray
define earlier like:
baseService()
.then(() => Promise.all(promisesArray))
.catch((err) => handleError(err));
then, the catch()
is run as expected but I have an error in the console
publish.js:45784 EXCEPTION: Error: Uncaught (in promise): ...
But I want to use that last solution as my array is generated according to some conditions by pushing the Promises to it. (and the first example is working just fine, I don't get what is different)
Adding catch to each of my promises while adding them to the array save my problem, but I'd like to find a better solution.
I would really appreciate some help with that.
PS: I am using angular2 with zone.js if it changes something