Using Promise.allSettled

Promise.allSettled will resolve when all the promises passed as an argument have fulfilled, regardless of whether they have resolved or rejected.

This allows you to define behavior for dealing with partial successes and failures when retrieving multiple resources from various locations. A common use case might be downloading and/or uploading several files to a remote server.

await Promise.allSettled(promises) will always resolve, as the promise returned by this API does not care whether the passed promises are resolved or rejected.

The Promise.allSettled resolution object is an array of promise resolutions and/or rejections. Await the Promise.allSettled statement and then iterate through the results, conditionally handling whether each promise was rejected or not.

We need to check each promise status individually:

const response = await Promise.allSettled(promises);
response.forEach((response) => {
      if (response.status === 'rejected') {
        // Handle your rejection
      } else {
        // Handle success