Skip to content

Commit

Permalink
Trap uncaught exceptions when running the REST API from the bin/www f…
Browse files Browse the repository at this point in the history
…ile.
  • Loading branch information
Jack Sheriff committed Jan 12, 2024
1 parent ed1818d commit 3c95847
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ async function runServer() {
server.close();
});

process.on('uncaughtException', (err, origin) => {
logger.error(`Uncaught exception: ${ err }`);
logger.error(`Exception origin: ${ origin }`);
logger.error(err.stack);

logger.error('Terminating app after uncaught exception');

process.exit(1);
});

// Wait for the server to close
const events = require('events');
await events.once(server, 'close');
Expand Down

0 comments on commit 3c95847

Please sign in to comment.