Theo Brown
Theo Brown
PPrisma
Created by Theo Brown on 5/9/2024 in #help-and-questions
findUniqueOrThrow does not throw a PrismaClientKnownRequestError - and NotFoundError is deprecated
Hey, I am writing an exception filter to handle Prisma errors, and was pleased to find the specific error types that have been implemented, e.g. PrismaClientKnownRequestError However, when using 'findUniqueOrThrow' and the record is not found, it does not produce a PrismaClientKnownRequestError - instead it just produces a normal error object with { "name": "NotFoundError", "code": "P2025", "clientVersion": "5.13.0", } Which doesn't really work very well with the exception filter looking for cases of PrismaClientKnownRequestError. When I add a case for NotFoundError, it says that this has been deprecated and "Please don´t rely on type checks to this error anymore. This will become a regular PrismaClientKnownRequestError with code P2025 in the future major version of the client. Instead of error instanceof Prisma.NotFoundError use error.code === "P2025"." How Should I be handling this? When will NotFoundError become a PrismaClientKnownRequestError? Am I doing something wrong? Any help will be much appreciated as I would really like to get a good error handling pattern working.
2 replies