Promise.all() rejects immediately when any one of its input promises rejects, discarding the results of all other promises even if they succeed. This fail-fast behavior is intentional but can be surprising when you need the results of the successful promises.
Why it happens
- •One of the parallel requests fails while others succeed.
- •A network error, timeout, or non-OK HTTP status causes one promise to reject.
- •An exception thrown inside one of the async operations propagates as a rejection.
Examples
Code that triggers the error
const results = await Promise.all([
fetch("/api/users"),
fetch("/api/missing-endpoint"), // returns 404, then .json() throws
fetch("/api/posts"),
]);Error output
Uncaught (in promise) SyntaxError: Unexpected token '<', "<!DOCTYPE..." is not valid JSON
How to fix it
Use Promise.allSettled() to get the results of all promises regardless of individual failures. Filter the results by status === 'fulfilled' to extract successful values. Use Promise.all() only when you want all-or-nothing semantics.
Fixed code
const results = await Promise.allSettled([
fetch("/api/users").then(r => r.json()),
fetch("/api/missing-endpoint").then(r => r.json()),
fetch("/api/posts").then(r => r.json()),
]);
const succeeded = results
.filter(r => r.status === "fulfilled")
.map(r => r.value);Related errors
Ready to practice your English at work?
Lingua-e has interactive exercises built around real developer conversations: standups, code reviews, retrospectives, and more. Practice until it comes naturally.
Try Lingua-e for free