From 775f5f34412c71d40bb495d6f19ced4d527586ca Mon Sep 17 00:00:00 2001 From: Henry Fontanier Date: Thu, 26 Oct 2023 15:49:10 +0200 Subject: [PATCH] enh: add global handler for uncaught exceptions/rejections (#2280) --- connectors/src/api_server.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/connectors/src/api_server.ts b/connectors/src/api_server.ts index c3036b07ed44..35abe8b32af2 100644 --- a/connectors/src/api_server.ts +++ b/connectors/src/api_server.ts @@ -27,6 +27,14 @@ import logger from "@connectors/logger/logger"; import { authMiddleware } from "@connectors/middleware/auth"; export function startServer(port: number) { + process.on("unhandledRejection", (reason, promise) => { + logger.error("Unhandled Rejection at:", promise, "reason:", reason); + }); + + process.on("uncaughtException", (error) => { + logger.error("Uncaught Exception thrown", error); + }); + const app = express(); // for health check -- doesn't go through auth middleware