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:
Roba Boru
2026-07-19 18:18:08 +03:00
parent 85cd6cdf2a
commit 1804fba5bb

View File

@@ -24,7 +24,11 @@ export class HttpExceptionFilter implements ExceptionFilter {
const request = ctx.getRequest();
let prismaMessage: string | null = null;
let prismaCode: string | null = null;
let prismaMeta: unknown = null;
if (exception instanceof PrismaClientKnownRequestError) {
prismaCode = exception.code;
prismaMeta = exception.meta;
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.`;
@@ -68,6 +72,7 @@ export class HttpExceptionFilter implements ExceptionFilter {
statusCode: status,
message,
error: exception instanceof Error ? exception.name : 'Error',
...(prismaCode ? { prismaCode, prismaMeta } : {}),
timestamp: new Date().toISOString(),
path: request.url,
...customFields,