From e2cf5d2e372353c7cd29c3cd4f5d7cec38ce0cea Mon Sep 17 00:00:00 2001 From: isra el Date: Sun, 7 Dec 2025 20:57:14 +0300 Subject: [PATCH] chore(api): ensure uncaught exceptions dont crash server --- api/src/main.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/api/src/main.ts b/api/src/main.ts index 2ef2cc4..7dc1bff 100644 --- a/api/src/main.ts +++ b/api/src/main.ts @@ -1,5 +1,5 @@ import 'dotenv/config' -import { VersioningType } from '@nestjs/common' +import { VersioningType, Logger } from '@nestjs/common' import { NestFactory } from '@nestjs/core' import { AppModule } from './app.module' import * as firebase from 'firebase-admin' @@ -7,6 +7,19 @@ import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger' import * as express from 'express' import { NestExpressApplication } from '@nestjs/platform-express' +// Global error handlers to prevent server crashes +const logger = new Logger('GlobalErrorHandler') + +process.on('uncaughtException', (error: Error) => { + logger.error('Uncaught Exception:', error.stack || error.message) + // Don't exit the process for uncaught exceptions in production + // process.exit(1) +}) + +process.on('unhandledRejection', (reason: any, promise: Promise) => { + logger.error('Unhandled Rejection at:', promise, 'reason:', reason) +}) + async function bootstrap() { const app: NestExpressApplication = await NestFactory.create(AppModule) const PORT = process.env.PORT || 3001