mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 16:28:12 +00:00
debug(passenger-api): expose Prisma error code in 500 response body
Adds prismaCode and prismaMeta fields to 500 responses so the exact Prisma error code (P2022, P2023, etc.) is visible in curl/Swagger without needing server log access. Temporary diagnostic aid. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -24,7 +24,11 @@ export class HttpExceptionFilter implements ExceptionFilter {
|
|||||||
const request = ctx.getRequest();
|
const request = ctx.getRequest();
|
||||||
|
|
||||||
let prismaMessage: string | null = null;
|
let prismaMessage: string | null = null;
|
||||||
|
let prismaCode: string | null = null;
|
||||||
|
let prismaMeta: unknown = null;
|
||||||
if (exception instanceof PrismaClientKnownRequestError) {
|
if (exception instanceof PrismaClientKnownRequestError) {
|
||||||
|
prismaCode = exception.code;
|
||||||
|
prismaMeta = exception.meta;
|
||||||
if (exception.code === 'P2003') {
|
if (exception.code === 'P2003') {
|
||||||
const field = (exception.meta?.field_name as string | undefined) ?? 'a related record';
|
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.`;
|
prismaMessage = `Cannot delete this record because it is still referenced by ${field}. Remove the related records first.`;
|
||||||
@@ -68,6 +72,7 @@ export class HttpExceptionFilter implements ExceptionFilter {
|
|||||||
statusCode: status,
|
statusCode: status,
|
||||||
message,
|
message,
|
||||||
error: exception instanceof Error ? exception.name : 'Error',
|
error: exception instanceof Error ? exception.name : 'Error',
|
||||||
|
...(prismaCode ? { prismaCode, prismaMeta } : {}),
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
path: request.url,
|
path: request.url,
|
||||||
...customFields,
|
...customFields,
|
||||||
|
|||||||
Reference in New Issue
Block a user