From a9e3b27cb52a83e42edb08a95ae2d7a8d5bfd4f1 Mon Sep 17 00:00:00 2001 From: CountBleck Date: Tue, 30 Aug 2022 15:26:46 -0700 Subject: [PATCH] Add UNSAFE last-resort measure to prevent crashes This is really unsafe, according to Node.js's docs (see link below). Therefore, this handler is only added if the UNSAFE_CONTINUE environment variable has a truthy value. https://nodejs.org/api/process.html#warning-using-uncaughtexception-correctly --- app.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app.js b/app.js index 499ef6e..76fb2a9 100644 --- a/app.js +++ b/app.js @@ -44,4 +44,12 @@ server.on('upgrade', (req, socket, head) => { server.listen(PORT); +if (process.env.UNSAFE_CONTINUE) + process.on("uncaughtException", (err, origin) => { + console.error(`Critical error (${origin}):`) + console.error(err) + console.error("UNSAFELY CONTINUING EXECUTION") + console.error() + }) + console.log(`Server running at http://localhost:${PORT}/.`);