Code QuizIntermediate

Promise.all vs Promise.allSettled

Learn why Promise.all short-circuits on the first rejection while Promise.allSettled waits for every promise.

Codejavascript
async function fetchAllUsers(ids) {
  const promises = ids.map(id => fetch(`/users/${id}`));
  // We want a report of which requests succeeded and which failed
  const results = await Promise.all(promises);
  return results.map(res => ({ ok: res.ok }));
}

The goal is to always get a result for every id even if some requests fail. What is the bug?