-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
Description
Problem
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.
tjhiggins