Tracking unhandled rejections
This feature allows you to track unhandled promise rejections. By using the currentlyUnhandled() function, you can retrieve an array of promises that were rejected and not yet handled at the time of the call.
const currentlyUnhandled = require('currently-unhandled')();
process.on('unhandledRejection', (reason, promise) => {
console.log('Unhandled Rejection at:', promise, 'reason:', reason);
// Application specific logging, throwing an error, or other logic here
});
// Later in the code, you can check for unhandled rejections
const unhandledRejections = currentlyUnhandled();
console.log(unhandledRejections);