Skip to content

Instantly share code, notes, and snippets.

@AleksejDix
Created December 10, 2021 08:15
Show Gist options
  • Save AleksejDix/81a7dd962f6ca4ae3628068f0ea32f28 to your computer and use it in GitHub Desktop.
Save AleksejDix/81a7dd962f6ca4ae3628068f0ea32f28 to your computer and use it in GitHub Desktop.
Handling Promise.all errors
const results = await Promise.all(promises.map(p => p.catch(e => e)));
const validResults = results.filter(result => !(result instanceof Error));
@AleksejDix
Copy link
Author

Also there is new way of doing this

Promise.allSettled(promises).
  then((results) => results.forEach((result) => console.log(result.status)));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment