Skip to content
Back to all posts
Technology

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.

2 min read

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

javascript
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:

javascript
{ 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

javascript
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.

javascript
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

javascript
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