Skip to content

Error Handling for Prisma #12

@vibbs

Description

@vibbs

the import from the tutorial

import { PrismaClientKnownRequestError } from '@prisma/client/runtime';

Is not working as expected, instead when I import like below as per the documentation it works fine:

import { Prisma } from '@prisma/client';

// and try to match error instance in this way
if (error instanceof Prisma.PrismaClientKnownRequestError) {
        console.log(error.message);
        if (error.code === 'P2002') {
          throw new ForbiddenException('Credentials taken');
        }
      }

Hope this helps if anyone following along faces the same issue.

Doc link referred: https://www.prisma.io/docs/concepts/components/prisma-client/handling-exceptions-and-errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions