Skip to content

Error Handling for Prisma #12

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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