How do you handle AggregateError from Promise.any in JavaScript?
Use try/catch. Check err instanceof AggregateError. Access err.errors (an array of all individual rejection reasons). This lets you see why each promise failed.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Promise Combinators: Common Mistakes in JavaScript
Using Promise.all for partial success (use allSettled), forgetting race can reject (use any), not handling AggregateError, race([]) never settles, not clearing timers in race, and expecting Promise.all to cancel other promises (it does not).
No. The other promises continue running; their results are just ignored. Promise.all does not cancel anything. For actual cancellation, use AbortController with fetch.
Because there are no promises to settle. The race has nothing to wait for, so it stays pending forever. Always check that the array is not empty before passing it to Promise.race.
Still have questions?
Browse all our FAQs or reach out to our support team
