Do you know what will be the output of this code?
JavaScript
Promise.all([
Promise.resolve(1),
Promise.reject(new Error("fail")),
Promise.resolve(3),
])
.then((values) => console.log(values))
.catch((err) => console.log(err.message));
Show answer and explanation
The answer is "fail".
Promise.all is all-or-nothing: it rejects with the first rejection reason and the fulfilled values are discarded. Promise.allSettled waits for every promise and reports each result.
For the happy path, see how to run API calls in parallel with Promise.all.