⚡ JavaScript: Fix a Promise.all Call Masking Which Request Failed
Promise.all() rejects with the reason of whichever promise fails first, and gives up no information about which of the other N promises in the array were still pending, already resolved, or also about to fail. For a batch of independent API calls, that means a single caught error tells you something failed, but not which endpoint, which payload, or whether three other requests failed right alongside it for a related reason.
🔎 The Problem
const results = await Promise.all([
fetchUser(id), fetchOrders(id), fetchInvoices(id), fetchNotes(id)
]);
// catch (err) { console.error(err) }
// logs only ONE error, e.g. "404 Not Found" - no idea if that
// was fetchOrders or fetchInvoices, or whether more than one failed
✅ Fix: Use allSettled() to Preserve Every Outcome
- Replace
Promise.all()withPromise.allSettled()when the calls are independent, then check each result’sstatusfield so a single failure doesn’t hide the outcome of everything else in the batch. - Tag each promise with its source before awaiting, e.g.
fetchOrders(id).catch(e => ({ source: 'orders', error: e })), so a caught error always carries enough context to log which specific request actually failed. - Reserve plain
Promise.all()for calls that are genuinely all-or-nothing — where one failing really should abort the rest — and useallSettled()everywhere the calls are independent and partial success is meaningful.
🚨 Why This Is Dangerous
- A monitoring dashboard built on caught
Promise.allerrors can report ‘one failure’ when three of four dependent services were actually down simultaneously, badly understating the real scope of an outage during an incident.
Promise.all tells you the batch failed. It was never built to tell you why, or how much of it actually survived.




