CodShot
JavaScript Public

Process Mixed Results with Promise.allSettled

Run independent asynchronous tasks and keep both successful and failed outcomes.

#javascript #promise #async #error-handling
JavaScript
async function loadDashboardResources() {
  const requests = [
    fetch('/api/profile').then((response) => response.json()),
    fetch('/api/projects').then((response) => response.json()),
    fetch('/api/notifications').then((response) => response.json()),
  ];

  const results = await Promise.allSettled(requests);

  return results.map((result, index) => {
    if (result.status === 'fulfilled') {
      return {
        index,
        ok: true,
        data: result.value,
      };
    }

    return {
      index,
      ok: false,
      error: result.reason instanceof Error
        ? result.reason.message
        : String(result.reason),
    };
  });
}

loadDashboardResources().then(console.table);

Snippet actions

CodShot user
CodShot user
Updated: 2026-08-06 18:36
Public snippets
0
Forks
CodShot AI Help
Ask about CodShot features, plans, workspace, AI limits, referrals, and public help topics.
Hi! I can help you understand how CodShot works. What would you like to know?
For account-specific or sensitive issues, please open a support ticket. Open support