Closed megane42 closed 10 months ago
Thanks for the PR @megane42. I like the approach, but it seems that we need to duplicate the status codes to the HttpStatus and again for the message.
What if we could include the custom message in the first object. Just an idea to either set the status or object {status: number, message: string}
app.useGlobalFilters(
new PrismaClientExceptionFilter(
httpAdapter,
// Prisma Error Code: HTTP Status Response
{
P2000: HttpStatus.BAD_REQUEST,
P2002: HttpStatus.CONFLICT,
P2025: { status: HttpStatus.NOT_FOUND, message: 'Resource not found' }
}
),
);
@marcjulian Hi, let me know if there is anything I can do to help merge this PR. Sorry to rush you like this 🙏
Hi @megane42, I haven't forgotten about your PR. I will try to find time to review and merge your PR soon.
Thanks for this PR, I really hope to get this finished ASAP because it's really important feature.
Greeting to you Devs.
The custom error message can be testet in the latest dev release.
npm i nestjs-prisma@0.23.0-dev.0
resolves #72
Examples
useGlobalFilters()
APP_FILTER
or
Results
Before
After
Note
Only status mappings are used for judging whether or not to handle Prisma errors. Message mappings are not used for it. So if the app setting is like this:
the nest app returns
500 Internal server error
whenP2028
happens. Note thatP2000
P2002
P2025
are always handled implicitly because they are hard-coded.