unhandledRejection - Using Promises - JavaScript | MDN

PHOTO EMBED

Thu Apr 01 2021 21:48:01 GMT+0000 (Coordinated Universal Time)

Saved by @pablomuro

process.on("unhandledRejection", (reason, promise) => {
  /* You might start here by adding code to examine the
   * "promise" and "reason" values. */
});
content_copyCOPY

One case of special usefulness: when writing code for Node.js, it's common that modules you include in your project may have unhandled rejected promises, logged to the console by the Node.js runtime. You can capture them for analysis and handling by your code—or just to avoid having them cluttering up your output—by adding a handler for the Node.js unhandledRejection event (notice the difference in capitalization of the name), like this:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises