Skip to content

Commit

Permalink
fix: add findUniqueOrThrow example (#6459)
Browse files Browse the repository at this point in the history
* fix: add `findUniqueOrThrow` example

* Update content/200-orm/500-reference/050-prisma-client-reference.mdx

---------

Co-authored-by: Nikolas <[email protected]>
  • Loading branch information
ankur-arch and nikolasburk authored Nov 27, 2024
1 parent 74ca13c commit 64f33cf
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions content/200-orm/500-reference/050-prisma-client-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -621,13 +621,22 @@ const result = await prisma.user.findUnique({

### `findUniqueOrThrow()`

<Admonition type="info">
:::note

We introduced `findUniqueOrThrow` in v4.0.0. It replaces the [`rejectOnNotFound`](#rejectonnotfound) option. `rejectOnNotFound` is deprecated in v4.0.0.

</Admonition>
:::

`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 <Model> found`.

Here’s an example of how it works:

`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`.
```ts
await prisma.user.findUniqueOrThrow({
where: {
id: 1,
},
});

`findUniqueOrThrow` differs from `findUnique()` as follows:

Expand Down

0 comments on commit 64f33cf

Please sign in to comment.