Advertisement

TrimwebsolutionsTrimwebsolutions

Problem and Solutions

Catch() is not handling rejection of promise in case multiple javascript Promises to settle with Promise.allSettled() in node.js ?

By M.K. Verma · 2 May 2022

Catch() is not handling rejection of promise in case multiple javascript Promises to settle with Promise.allSettled() in node.js ?

The catch statement will be executed when the error occurs. As the Promise.allSettled() always resolves, you can manually throw an error i.e.

 

if(posts.status === "rejected"){
  throw new Error('a status was rejected'); 
}