I have a sequence of async functions that can be resolved or rejected. This functions must be executed in the correct sequence and depend one on other. So, i used 3 async functions and a try catch block. The problem is that when I reject some of the promises in the async functions, the catch block dont get the error sended on the reject callback. How can I get the error sended on reject? (code bellow)
Or should I use promise chaining? I would like to avoid this...
const methods = {
methodOne: async output => {
return new Promise( (resolve, reject) => {
if(error)
reject(error) // want to get this error in try/catch block
else
resolve()
})
})
},
methodTwo: async () => {
return new Promise( (resolve, reject) => {
if(error)
reject(error)
else
resolve('output')
})
})
},
methodThree: async () => {
return new Promise( (resolve, reject) => {
if(error)
reject(error)
else
resolve()
})
})
},
runMethods: async () => {
return new Promise( async (resolve, reject) => {
try {
await methods.methodOne()
const output = await methods.methodTwo()
await methods.methodThree(output)
resolve()
} catch(error) {
console.log(error)
reject(error)
}
})
}
}