⚡ Fix Promise.any Throwing an Unhelpful Aggregate Error
Promise.any() resolves as soon as any one of its input promises fulfills, which is exactly what makes it useful for racing redundant requests, but when every single promise rejects it throws an AggregateError whose default .message is just ‘All promises were rejected’ — the individual, much more useful rejection reasons are nested inside its .errors array, and code that logs the caught error directly without unwrapping that array ends up with a log line that explains nothing about what actually went wrong.
🔎 The Problem
try {
const result = await Promise.any([fetchA(), fetchB(), fetchC()]);
} catch (err) {
console.error(err.message);
// Logs only: "All promises were rejected"
// The three actual underlying errors are sitting in err.errors,
// completely invisible in this log line
}
✅ Fix: Unwrap the Errors Array Before You Log or Report
- Check
err instanceof AggregateErrorin the catch block and logerr.errors(each individual rejection reason) rather than just the top-level message, so the actual failures are visible. - When reporting to an error-tracking service, flatten
err.errorsinto separate breadcrumbs or tags rather than sending the single generic AggregateError message, which on its own is nearly useless for triage. - If the sources being raced have meaningfully different failure modes, label each promise (e.g. wrap with a tag before racing) so the unwrapped errors can be matched back to which source actually failed.
Promise.any’s error message is a summary, not a diagnosis — the actual reasons are one property access away.






