You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem with the global one is that you'd want to change the return type for the models you decide to reject. Instead of User | null, it should be User, since it's going to reject not found users anyway.
Open Question: does local rejectOnNotFound adjust the signature?
Suggested solution
My vote would be to remove this API and replace it with a few new methods:
prisma.user.mustFindUnique()
prisma.user.mustFindFirst()
Then everything is explicit, local and the return types can be properly altered.
Alternatives
I'm guessing our engineers have thought of other solutions :-)
I don't think removing global error handlers is a good idea. We rely on custom errors for each model and removing this will cause too much code repetition in our code base, or need to replace al prisma calls with a wrapper function.
Fixing the global signature and allowing to pass our custom errors like described in #13497 seems like a more sustainable solution. But that's just me 🙏
@cawa-93 you're using findFirst I think you would need to use findFirstOrThrow new method and use latest prisma to actually catch Prisma.NotFoundError. Am I wrong @matthewmueller ?
Found this but on data-proxy is that code P5003 correct prisma team and can I look for that or PrismaNotFoundError?
I don't think we're using prisma data proxy yet tho...
@agustif the Data Proxy error is irrelevant, the one you are looking for is the second one. There's no error code, you can use the instanceof operator:
Activity
dpetrick commentedon May 25, 2022
Internal spec: https://www.notion.so/prismaio/Deprecate-rejectOnNotFound-59a9c7711f2e45b5b5bb29d5cebcdad5
zomars commentedon May 27, 2022
I don't think removing global error handlers is a good idea. We rely on custom errors for each model and removing this will cause too much code repetition in our code base, or need to replace al prisma calls with a wrapper function.
zomars commentedon May 27, 2022
Fixing the global signature and allowing to pass our custom errors like described in #13497 seems like a more sustainable solution. But that's just me 🙏
feat(client): Add `findUniqueOrThrow` and `findFirstOrThrow` methods
feat(client): Add `findUniqueOrThrow` and `findFirstOrThrow` methods
7 remaining items
matthewmueller commentedon Jun 23, 2022
They throw
NotFoundErrorerrors. Should be accessible in the Prisma namespace, but let us know if it's not!cawa-93 commentedon Jun 27, 2022
@matthewmueller
it's not.

zomars commentedon Jun 27, 2022
@cawa-93 you're using
findFirstI think you would need to usefindFirstOrThrownew method and use latest prisma to actually catchPrisma.NotFoundError. Am I wrong @matthewmueller ?feat(client): Export NotFoundError in Prisma namespace
feat(client): Export NotFoundError in Prisma namespace
feat(client): Export NotFoundError in Prisma namespace
feat(client): Export NotFoundError in Prisma namespace (#14076)
agustif commentedon Aug 12, 2022
I think it's Prisma.notFound
.catch((e) => { if (e instanceof Prisma.notFound) { throw new HttpError({ statusCode: 404, message: "User not found" }); } });zomars commentedon Aug 12, 2022
The thing is the
throw new HttpErrorwon't be respected globally unless this has been fixed already.EDIT: seems like global errors have been deprecated
agustif commentedon Aug 12, 2022
Found this but on
data-proxyis that codeP5003correct prisma team and can I look for that or PrismaNotFoundError?I don't think we're using prisma data proxy yet tho...
https://github.com/prisma/prisma/blob/c1d4f6ea4a0499759dcc1e43cc6c846ccb8051a8/packages/engine-core/src/data-proxy/errors/NotFoundError.ts#L10
Prob this, but no code for some reason? https://github.com/prisma/prisma/blob/96a85ed0334afc0d7c56c9bba7b64af0f9969a2d/packages/client/src/runtime/utils/rejectOnNotFound.ts#L6-L16
Also relevant tests

aqrln commentedon Aug 15, 2022
@agustif the Data Proxy error is irrelevant, the one you are looking for is the second one. There's no error code, you can use the
instanceofoperator:We should probably improve the docs here!
LuanEdCosta commentedon Nov 30, 2022
I've noticed that the
NotFoundErroris not on the documentation.https://www.prisma.io/docs/reference/api-reference/error-reference
Edit 1
The
NotFoundErroris mentioned only here: https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#findfirstorthrowFelixZY commentedon May 21, 2023
Prisma.NotFoundErroris now deprecated: https://github.com/prisma/prisma/blob/f073dc12a990876bb05a0d4bd5e2fe461b6787a8/packages/client/src/runtime/utils/rejectOnNotFound.ts#L13-L18