Skip to content

Commit

Permalink
fix: properly handle uncaught exceptions using uncaughtExceptionMonitor
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Jan 7, 2025
1 parent 2376a5e commit 00c31ed
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,9 @@ class Graceful {
});

// handle uncaught exceptions
process.once('uncaughtException', (err) => {
// always log to console the error (e.g. so we can see it on pm2 logs)
console.error(err);
if (this.config.hideMeta)
this.config.logger.error(err, { [this.config.hideMeta]: true });
else this.config.logger.error(err);
// artificial timeout to allow logger to store uncaught exception to db
if (this.config.uncaughtExceptionTimeoutMs)
setTimeout(() => {
process.exit(1);
}, this.config.uncaughtExceptionTimeoutMs);
else process.exit(1);
process.on('uncaughtExceptionMonitor', (err, origin) => {
console.error(err, { origin });
this.config.logger.fatal(err, { origin });
});

// handle windows support (signals not available)
Expand Down

0 comments on commit 00c31ed

Please sign in to comment.