I have a function that calls itself recursively with different input when catching an error:
function getSomething(inputs, index) {
var index = index || 0
, indexMax = inputs.length - 1
return new Promise((resolve, reject) => {
//inputs[index].staff is an array and getSomethingElse returns a Promise
Promise.all(inputs[index].staff.map(getSomethingElse))
.then(output => {
resolve(output)
})
.catch(reason => {
if(index<indexMax)
getSomething(inputs, index+1);
else
reject(reason);
})
})
}
getSomething(myInputs)
.then(output => {
console.log('resolved with this:'+output);
})
.catch(reason => {
console.log('rejected because of this:'+reason);
});
I get UnhandledPromiseRejectionWarning: Unhandled promise rejection error from getSomethingElse rejection. I think this rejection is not catched in the first function call as it expected it. How can I call the reject of the first function call ? or should I bring the first promise with me as an argument in each function call ?