From eb594e79d2bb47a04310f236231818495a4228e6 Mon Sep 17 00:00:00 2001 From: Phill Pover Date: Mon, 7 Apr 2025 10:22:32 +0100 Subject: [PATCH] Adding error handling --- backend/src/main.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/src/main.ts b/backend/src/main.ts index 148c29d..d2a4d7a 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -13,7 +13,16 @@ async function bootstrap() { allowedHeaders: 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept, Observe', }); - app.useGlobalPipes(new ValidationPipe({ transform: true })); + app.useGlobalPipes(new ValidationPipe({ + transform: true, + exceptionFactory: (errors) => { + const result = errors.map((error) => ({ + property: error.property, + message: error.constraints[Object.keys(error.constraints)[0]], + })); + return new UnprocessableEntityException(result); + }, + })); await app.listen(process.env.PORT ?? 3000); } bootstrap();