I had a few promises that do the same sort of thing, I was hoping to add a catch
statement programatically to them and then run Promise.all on them. I had a few ideas for achieving this but it keeps blowing up in my face.
let promises = [
Promise.reject('derp'), // Naïve test
new Promise((resolve, reject) => { // Assumed this ran out of main loop
reject('whayyy')
}),
new Promise((resolve, reject) => { // really assumed this ran out of main loop
process.nextTick(() => reject('nooooon'))
})
]
//fails
for(let promise of promises){
promise.catch((err) => { return 'fixed programatically'} )
}
Promise.all(promises).then((things) => {
console.log("Expect to make it here with no problems")
console.log(things)
})
I keep getting this for all three promises:
(node:25148) UnhandledPromiseRejectionWarning: derp|whayy|nooooon
(node:25148) UnhandledPromiseRejectionWarning: Unhandled promise rejection.
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
Does anyone know how to properly do this?
Edit: I'm not sure why, I re-ran the original code and no longer get any errors. :(