chore(api): ensure uncaught exceptions dont crash server

This commit is contained in:
isra el
2025-12-07 20:57:14 +03:00
parent d6d52e80cf
commit e2cf5d2e37

View File

@@ -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<any>) => {
logger.error('Unhandled Rejection at:', promise, 'reason:', reason)
})
async function bootstrap() {
const app: NestExpressApplication = await NestFactory.create(AppModule)
const PORT = process.env.PORT || 3001