From e63fb2cc274faba851fee9c18e2b870cc9a7d219 Mon Sep 17 00:00:00 2001 From: joshua Date: Wed, 26 Aug 2026 09:03:15 +0200 Subject: [PATCH] Stop crashing the server on unhandled promise rejections A single missed .catch() anywhere in the notification code (email/WhatsApp sending) previously took down the whole process via process.exit(1). Log the error instead and keep running. --- CHANGELOG.md | 1 + backend/src/index.js | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a568876..2a5ffaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project follows [Semantic Versioning](https://semver.org/). ### Fixed +- The server used to hard-crash (`process.exit(1)`) on any unhandled promise rejection, so a single missed error handler anywhere in the app's fire-and-forget notification code (email/WhatsApp sending) could take the whole server down. It now logs the error and keeps running. - Accounts created on someone's behalf (at-the-door walk-in registration, or manual registration from the Admin/Supervisor dashboard) now get their activation link (email or WhatsApp, whichever they have) sent immediately when the account is created, instead of only on their first failed login attempt — matching what the Terms of Use already promised. - Manual registration with a real email address used to create the account already active with a fixed, undisclosed password (`Hope123`) — the visitor had no way to know it. That account is now created inactive and gets the same immediate activation link, so the visitor sets their own password — unless a password was supplied directly (see below), in which case it's activated immediately with no link needed. - The self-service kiosk's "Create an account" password field never actually worked — the account was always created with a different password behind the scenes, so visitors who set one couldn't log in with it. Manual registration now honours a caller-supplied password and activates the account immediately instead of discarding it. diff --git a/backend/src/index.js b/backend/src/index.js index 9810b88..d63ad7d 100644 --- a/backend/src/index.js +++ b/backend/src/index.js @@ -1265,11 +1265,12 @@ app.listen(PORT, () => { } }); -// Handle unhandled promise rejections +// Log unhandled promise rejections without killing the server, since a single +// missed .catch() on fire-and-forget notification code (email/WhatsApp sends) +// would otherwise take the whole app down. process.on('unhandledRejection', (err) => { - console.log('UNHANDLED REJECTION! Shutting down...'); - console.log(err.name, err.message); - process.exit(1); + console.error('UNHANDLED REJECTION!', err?.name, err?.message); + console.error(err?.stack || err); }); module.exports = { app, prisma }; \ No newline at end of file