Using Promise.allSettled() to Handle Partial Failures
Keep successful asynchronous results when other requests fail. Learn Promise.allSettled outcomes, error handling, and safe concurrency patterns.
TechSilo
Technology writer & developer
When independent operations can fail separately, Promise.all() may not give you the result you want. It rejects as soon as one input rejects, even though the other operations continue running. Promise.allSettled() waits for every input and tells you which ones succeeded.
Compare the behavior
const tasks = [
Promise.resolve({ name: 'profile' }),
Promise.reject(new Error('Recommendations unavailable')),
Promise.resolve({ name: 'settings' }),
];
const outcomes = await Promise.allSettled(tasks);
console.log(outcomes);Each outcome has one of two shapes:
{ status: 'fulfilled', value: someValue }
{ status: 'rejected', reason: someError }The results remain in input order, not completion order. A rejected operation does not turn the entire allSettled result into a rejection.
Extract successful results safely
async function loadDashboard() {
const requests = [
fetch('/api/profile'),
fetch('/api/notifications'),
fetch('/api/preferences'),
];
const results = await Promise.allSettled(requests);
return results.map((result, index) => ({
section: ['profile', 'notifications', 'preferences'][index],
ok: result.status === 'fulfilled' && result.value.ok,
response: result.status === 'fulfilled' ? result.value : null,
error: result.status === 'rejected' ? result.reason : null,
}));
}Important: fetch() usually resolves on HTTP 404 or 500. Test response.ok or throw deliberately if you want HTTP errors treated as rejected promises.
async function fetchJson(url) {
const response = await fetch(url);
if (!response.ok) {
throw new Error(url + ': HTTP ' + response.status);
}
return response.json();
}Present partial success in the UI
const urls = ['/api/a', '/api/b', '/api/c'];
const settled = await Promise.allSettled(urls.map(fetchJson));
const data = settled.flatMap((result, index) =>
result.status === 'fulfilled'
? [{ source: urls[index], value: result.value }]
: []
);
const failures = settled.flatMap((result, index) =>
result.status === 'rejected'
? [{ source: urls[index], reason: String(result.reason) }]
: []
);You can render available sections and show a retry button only for the failed ones.
When not to use it
- When all operations must succeed for data consistency, use Promise.all() or a coordinated transaction.
- When you need the first successful result, consider Promise.any().
- When you have thousands of requests, use a concurrency limit. allSettled does not throttle network activity.
- When operations must be canceled, pass an AbortSignal; allSettled does not cancel unfinished work.
Practical checklist
Validate HTTP status, report failed operations with meaningful context, avoid leaking sensitive error objects into the UI, and retry only idempotent requests unless you have deduplication in place. For debugging result payloads, use TechSilo's [JSON Formatter](/tools/json-formatter).
Want to put this into practice?
Explore TechSilo's free developer tools for practical utilities you can use directly in your browser.
Related blog posts
Console.log Alternatives for Efficient JavaScript Debugging
Use browser breakpoints, console.table, console.trace, timing APIs, and structured logs to debug without flooding production consoles.
Read postJavaScript Destructuring Defaults: Avoid Undefined and Subtle Bugs
Use default values in object and array destructuring correctly, including nested options, null behavior, and function parameters.
Read postUnderstanding JavaScript Closures: Scope, State, and Common Mistakes
Learn how JavaScript closures retain lexical scope, build private state, and cause stale values in callbacks, with copyable examples.
Read postUnderstanding WebAssembly: When and How to Use Wasm
Understand WebAssembly modules, JavaScript integration, browser sandboxing, and the workloads where Wasm helps performance.
Read postRegex Anchors: Match the Whole Input, Not Just a Substring
Learn how start and end anchors work, when to use Python fullmatch, how JavaScript handles final newlines, and why regex validation needs more than anchors.
Read post