Getting Started

Before starting you need to be authenticated, since the package is hosted within a private npm registry, the authentication steps are described before.

Authentication chevron-right

First, you need to install the package using the following command:

npm i @tradinos/cms-backend-prisma-errors

Second in your module you need to use PrismaErrorExceptionFilter exception filter

import { Module } from '@nestjs/common';
import { APP_FILTER } from '@nestjs/core';
import { PrismaErrorExceptionFilter } from '@tradinos/cms-backend-prisma-errors';

@Module({
  providers: [
    {
      provide: APP_FILTER,
      useClass: PrismaErrorExceptionFilter,
    },
  ],
})
export class AppModule {}

Here we are! We have a Prisma error handler.

Default Handlers

Out of the box, we have handlers for 4 error codes:

Prisma Error Code
Mapped Http Exception

P2025

400 Bad Request

P2003

400 Bad Request

P2018

404 Not Found

P2002

400 Bad Request

And we are continuously working to handle additional errors. But, you can add your own mappers or override one of the above handlers, will get to how to do that in the next page.

Last updated