Injectable Error Handling With Prisma In NestJS
Injectable function for error formatting in Prisma. Handles P2002, P2003, P2025 & more errors with custom error messages.
I have created it Injectable. You can use this functionally also.
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { Injectable } from '@nestjs/common';
import {
PrismaClientInitializationError,
PrismaClientKnownRequestError,
PrismaClientRustPanicError,
PrismaClientValidationError,
} from '@prisma/client/runtime/library';
interface ErrorMessage {
path: string;
message: string;
}
@Injectable()
export class PrismaExceptionFormatter {
formatPrismaError(exception: PrismaClientKnownRequestError): ErrorMessage[] {
const errorMessages: ErrorMessage[] = [];
sw...