Skip to content

Commit

Permalink
fix: add findUniqueOrThrow example
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur-arch authored Nov 27, 2024
1 parent 798943b commit e1bb5d6
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 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,29 @@ 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`.

`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:

Expand Down

0 comments on commit e1bb5d6

Please sign in to comment.