mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 17:45:42 +00:00
Tour package booking, app release, new endpoints, more updates and fixes
This commit is contained in:
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user