Skip to content

Commit 64f33cf

Browse files
fix: add findUniqueOrThrow example (#6459)
* fix: add `findUniqueOrThrow` example * Update content/200-orm/500-reference/050-prisma-client-reference.mdx --------- Co-authored-by: Nikolas <[email protected]>
1 parent 74ca13c commit 64f33cf

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,13 +621,22 @@ const result = await prisma.user.findUnique({
621621

622622
### `findUniqueOrThrow()`
623623

624-
<Admonition type="info">
624+
:::note
625625

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

628-
</Admonition>
628+
:::
629+
630+
`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`.
631+
632+
Here’s an example of how it works:
629633

630-
`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`.
634+
```ts
635+
await prisma.user.findUniqueOrThrow({
636+
where: {
637+
id: 1,
638+
},
639+
});
631640

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

0 commit comments

Comments
 (0)