[javascript] Handling errors in Promise.all

We can handle the rejection at the individual promises level, so when we get the results in our result array, the array index which has been rejected will be undefined. We can handle that situation as needed, and use the remaining results.

Here I have rejected the first promise, so it comes as undefined, but we can use the result of the second promise, which is at index 1.

_x000D_
_x000D_
const manyPromises = Promise.all([func1(), func2()]).then(result => {_x000D_
    console.log(result[0]);  // undefined_x000D_
    console.log(result[1]);  // func2_x000D_
});_x000D_
_x000D_
function func1() {_x000D_
    return new Promise( (res, rej) => rej('func1')).catch(err => {_x000D_
        console.log('error handled', err);_x000D_
    });_x000D_
}_x000D_
_x000D_
function func2() {_x000D_
    return new Promise( (res, rej) => setTimeout(() => res('func2'), 500) );_x000D_
}
_x000D_
_x000D_
_x000D_