Skip to main content
Version: 1.x

Error Handling

ZenStack's enhancements to Prisma clients are transparent proxies, so normal errors thrown from a Prisma client simply pass through, and you can handle them the same way as you do in a regular Prisma project. It's good to read these references from Prisma:

The enhanced Prisma client can throw extra errors when an operation is rejected by access policies or its data fails validation rules. To keep a consistent programming experience, a PrismaClientKnownRequestError is thrown with code P2004 is used in such cases:

throw new PrismaClientKnownRequestError(message, {
clientVersion: getVersion(),
code: 'P2004',
meta: ...

The error contains a meta field providing more information about the error. It contains the following fields:

  • reason

    A string field indicating the detailed reason of the rejection. Its value can be one of the following:


      CRUD failed because of access policy violation.


      CRUD succeeded but the result was not readable (violating "read" access policies).


      CRUD failed because of a data validation error.

  • zodErrors

    An object field containing the raw Zod validation errors. Only present if the reason is DATA_VALIDATION_VIOLATION. See Zod documentation for more details.

Feel free to ask questions, give feedback, or report issues.

Don't Spam

You can edit/delete your comments by going directly to the discussion, clicking on the 'comments' link below