Skip to main content

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:

When you use withPolicy or withPresets enhancements, the wrapped 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:

ts
throw new PrismaClientKnownRequestError(message, {
clientVersion: getVersion(),
code: 'P2004',
});
ts
throw new PrismaClientKnownRequestError(message, {
clientVersion: getVersion(),
code: 'P2004',
});