Skip to content

Commit

Permalink
fix: always console.error (e.g. for pm2 log output)
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Dec 14, 2024
1 parent 23ca6f8 commit de5f734
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ class Graceful {
// handle uncaught promises
// <https://nodejs.org/api/process.html#event-unhandledrejection>
process.on('unhandledRejection', (err) => {
// we don't want to log here, we want to throw the error
// so that processes exit or bubble up to middleware error handling
// always log to console the error (e.g. so we can see it on pm2 logs)
console.error(err);
// we want to throw so that processes exit or bubble up to middleware error handling
// we need to support listening to unhandledRejections (backward compatibility)
// (even though node is deprecating this in future versions)
// <https://developer.ibm.com/blogs/nodejs-15-release-blog/>
Expand All @@ -97,6 +98,8 @@ 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);
Expand Down

0 comments on commit de5f734

Please sign in to comment.