Skip to content

Commit 00c31ed

Browse files
committed
fix: properly handle uncaught exceptions using uncaughtExceptionMonitor
1 parent 2376a5e commit 00c31ed

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

index.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,9 @@ class Graceful {
9797
});
9898

9999
// handle uncaught exceptions
100-
process.once('uncaughtException', (err) => {
101-
// always log to console the error (e.g. so we can see it on pm2 logs)
102-
console.error(err);
103-
if (this.config.hideMeta)
104-
this.config.logger.error(err, { [this.config.hideMeta]: true });
105-
else this.config.logger.error(err);
106-
// artificial timeout to allow logger to store uncaught exception to db
107-
if (this.config.uncaughtExceptionTimeoutMs)
108-
setTimeout(() => {
109-
process.exit(1);
110-
}, this.config.uncaughtExceptionTimeoutMs);
111-
else process.exit(1);
100+
process.on('uncaughtExceptionMonitor', (err, origin) => {
101+
console.error(err, { origin });
102+
this.config.logger.fatal(err, { origin });
112103
});
113104

114105
// handle windows support (signals not available)

0 commit comments

Comments
 (0)