PrismaP
Prisma2mo ago
5 replies
nb

PrismaClientKnownRequestError

I'm receiving a PrismaClientKnownRequestError with err.code === "P2002" (unique constraint violation), but err.meta.target is always undefined in the latest Prisma versions.

Previously, err.meta.target contained the list of fields that caused the constraint violation. Now that it's undefined, there is no way to determine which fields triggered the error — especially when a model has multiple unique constraints or compound unique indexes.

This creates a problem for implementing a global middleware/error handler, because we cannot identify which specific field (or combination of fields) violated the unique constraint.

Question

If err.meta.target is no longer available, what is the recommended way to retrieve the failing fields in a global error handler?
Was this page helpful?