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
{{ message }}
Repository navigation
Add model info to PrismaClientKnownRequestError #20724
I have global exception filter for NestJS, and it's catcher only have error instance of PrismaClientKnownRequestError. This execption filter needs somehow to know, what model is related to this error, e.g. to provide custom error message, related to model name.
Real example - trying to create user, but user with provided email exists in database. Exception filter uses error code (P2002) to detect this is unique constraint error or something else, but it still doesn't know what model it's related for.
Suggested solution
Add model name to error metadata, e.g.:
{meta: {model: 'User',target: ['email']}}
Alternatives
Imho best approach will be attaching custom metadata for any query, e.g.:
prismaClient.user.create({data: {
...
},customMetadata: {
... // any data engineer wants to attach},});
Idk how it's possible and/or type safe, but this grants far more flexibility than current usage.
@AikoRamalho sure. This place in our code would probably be a good starting point. You can find our dev environment setup instructions here and testing instructions here.
Looking forward to your contribution and let me know if you need help at any point.
Activity
EizFeren commentedon Aug 17, 2023
I've done somesing similar to described in
Suggested solution, but... It's deprecated middlewareSevInf commentedon Aug 18, 2023
Hi @EizFeren.
In meantime, instead of deprecated middleware, you can use query extension:
EizFeren commentedon Aug 18, 2023
Ty, I'll use this. But, I think it's good idea to add model name to error metadata by default, this will be very usefull
AikoRamalho commentedon Nov 14, 2023
Hey!
I would love to work on it.
SevInf commentedon Nov 15, 2023
@AikoRamalho sure. This place in our code would probably be a good starting point. You can find our dev environment setup instructions here and testing instructions here.
Looking forward to your contribution and let me know if you need help at any point.