Tour package booking, app release, new endpoints, more updates and fixes

This commit is contained in:
Stephanos A
2026-07-05 00:28:06 +03:00
parent 868639084c
commit 595be6e123
68 changed files with 2773 additions and 787 deletions

View File

@@ -6,6 +6,7 @@ import {
HttpStatus,
Logger,
} from '@nestjs/common';
import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library';
@Catch()
export class HttpExceptionFilter implements ExceptionFilter {
@@ -22,15 +23,27 @@ export class HttpExceptionFilter implements ExceptionFilter {
const response = ctx.getResponse();
const request = ctx.getRequest();
let prismaMessage: string | null = null;
if (exception instanceof PrismaClientKnownRequestError) {
if (exception.code === 'P2003') {
const field = (exception.meta?.field_name as string | undefined) ?? 'a related record';
prismaMessage = `Cannot delete this record because it is still referenced by ${field}. Remove the related records first.`;
} else if (exception.code === 'P2025') {
prismaMessage = 'Record not found.';
}
}
const status =
exception instanceof HttpException
? exception.getStatus()
: HttpStatus.INTERNAL_SERVER_ERROR;
: prismaMessage
? HttpStatus.BAD_REQUEST
: HttpStatus.INTERNAL_SERVER_ERROR;
const messageRaw =
exception instanceof HttpException
? exception.getResponse()
: 'Internal server error';
: prismaMessage ?? 'Internal server error';
const message =
typeof messageRaw === 'string'