notiz-dev / nestjs-prisma

Easy Prisma support for your NestJS application
https://nestjs-prisma.dev
MIT License
572 stars 49 forks source link

feat: add option to use generic http messages in Prisma exception filter #72

Closed recursive-beast closed 10 months ago

recursive-beast commented 1 year ago

Currently, the Prisma exception filter provided by the package maps Prisma exceptions to their corresponding HTTP exceptions, but the message of the HTTP exception is the same as the message of the underlying Prisma exception. This can result in error messages that are explicit.

I am willing to work on a pull request so that this response:

{
    "statusCode": 404,
    "message": "Not Found"
}

is sent instead of this response:

{
    "statusCode": 404,
    "message": "[P2025]: An operation failed because it depends on one or more records that were required but not found. No 'User' record(s) (needed to inline the relation on 'FriendInvitation' record(s)) was found for a nested connect on one-to-many relation 'receivedFriendInvitations'."
}

But I'm not sure how to approach this.

marcjulian commented 10 months ago

The custom error message can be testet in the latest dev release.

npm i nestjs-prisma@0.23.0-dev.0