diff --git a/content/200-orm/500-reference/050-prisma-client-reference.mdx b/content/200-orm/500-reference/050-prisma-client-reference.mdx index eadc33a2d1..c261dad180 100644 --- a/content/200-orm/500-reference/050-prisma-client-reference.mdx +++ b/content/200-orm/500-reference/050-prisma-client-reference.mdx @@ -621,13 +621,29 @@ const result = await prisma.user.findUnique({ ### `findUniqueOrThrow()` - +:::note We introduced `findUniqueOrThrow` in v4.0.0. It replaces the [`rejectOnNotFound`](#rejectonnotfound) option. `rejectOnNotFound` is deprecated in v4.0.0. - +::: + +`findUniqueOrThrow` retrieves a single data record similarly to [`findUnique()`](#findunique). However, if no record is found, it throws a `NotFoundError` with a message like: `No found`. -`findUniqueOrThrow` retrieves a single data record in the same way as [`findUnique()`](#findunique). However, if the query does not find a record, it returns `NotFoundError: No User found error`. +Here’s an example of how it works: + +```ts +await prisma.model.findUniqueOrThrow({ + where: { + id: 1, + }, +}); +``` + +:::note + +Replace `model` with the name of your Prisma model, e.g., `prisma.user.findUniqueOrThrow` or `prisma.post.findUniqueOrThrow`. + +::: `findUniqueOrThrow` differs from `findUnique()` as follows: