Prisma ORM

Lesson 08 · 10 min

Prisma errors: P2002, P2025

The database refused — turn its refusal into a clear API response.

When the database rejects a query, Prisma throws Prisma.PrismaClientKnownRequestError with a code field. The most common: P2002 — a unique constraint failed (the email is taken), P2025 — the record for update or delete wasn't found, P2003 — a foreign key constraint failed. Catch them and turn them into 409, 404, or 400, and leave everything else as 500.

Sign in to continue

The rest of this lesson opens after sign up

The first lesson of every course is open without an account. To read on, solve the practice and use Ask, create a free account or log in.