Promise.all() — Handle all rejected promises
In this article, I use the Axios library as an example. It is a small AJAX library, that you can call like
This returns a promise that resolves when the AJAX is successful, and rejects when failes.
All the individual promises will be executed parallely, but if any of the promise rejects, the overall promise will also get rejected, and there will be no way to know if the other promises got resolved or rejected.
Here is what you can do! Simply catch the individual promises, and store the errors manually
When we .catch() a Promise, the propogation of the reject will be stopped, therefore the combined Promise will never reject.
Note that, if any of the Promises get rejected, the resolved value in the .then() block, for the corresponding Promise will be undefined.
The above example was just a proof of concept, you can even do some fancy stuff like:
Hope you found this little article useful. Thanks for reading!