From 1da4feeb895a13d0a0ae754bd716a84e8186d081 Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Thu, 4 Apr 2024 23:18:00 +0200 Subject: [PATCH] fix(backend): crash on unhandled promise rejections --- backend/src/auth/auth.service.ts | 2 +- backend/src/main.ts | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/backend/src/auth/auth.service.ts b/backend/src/auth/auth.service.ts index dbd69b86..e25445e1 100644 --- a/backend/src/auth/auth.service.ts +++ b/backend/src/auth/auth.service.ts @@ -99,7 +99,7 @@ export class AuthService { include: { resetPasswordToken: true }, }); - if (!user) throw new BadRequestException("User not found"); + if (!user) return; // Delete old reset password token if (user.resetPasswordToken) { diff --git a/backend/src/main.ts b/backend/src/main.ts index 6e4f7545..f985a3ef 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -1,4 +1,8 @@ -import { ClassSerializerInterceptor, ValidationPipe } from "@nestjs/common"; +import { + ClassSerializerInterceptor, + Logger, + ValidationPipe, +} from "@nestjs/common"; import { NestFactory, Reflector } from "@nestjs/core"; import { NestExpressApplication } from "@nestjs/platform-express"; import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger"; @@ -6,8 +10,8 @@ import * as bodyParser from "body-parser"; import * as cookieParser from "cookie-parser"; import * as fs from "fs"; import { AppModule } from "./app.module"; -import { DATA_DIRECTORY } from "./constants"; import { ConfigService } from "./config/config.service"; +import { DATA_DIRECTORY } from "./constants"; async function bootstrap() { const app = await NestFactory.create(AppModule); @@ -15,6 +19,7 @@ async function bootstrap() { app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector))); const config = app.get(ConfigService); + app.use( bodyParser.raw({ type: "application/octet-stream", @@ -42,5 +47,8 @@ async function bootstrap() { } await app.listen(parseInt(process.env.PORT) || 8080); + + const logger = new Logger("UnhandledAsyncError"); + process.on("unhandledRejection", (e) => logger.error(e)); } bootstrap();