Skip to content Skip to sidebar Skip to footer

How To Correctly Trap And Read Any Errors Generated In A Promise.all Call?

I currently have a node.js/graphql micro service that uses Promise.all to call another micro service via apolloFetch. My Promise.all part seems to be working ok but I'm trying to h

Solution 1:

Your ErrorsArray will always contain at most ONE error. This is because Promise.all either resolve all promises or fail (and reject) after the first error it encounters.

Simply put, there's no need for an array here since there's no scenario where you have multiple exceptions.

If you really want to have a "chain" like logic, you should look into Observables. You can convert your Promises into Observables using rxjs and more specifically with the catchError and switchMap operators

Post a Comment for "How To Correctly Trap And Read Any Errors Generated In A Promise.all Call?"