Closed mathcrln closed 2 years ago
After many hours debugging and reading all sorts of documentations as to why this would happen, I realize about the silly mistake I made: I was testing my API Routes with Insomnia/Postman and forgot to set the "ContentType: application/json" header in the request. Once I did that, everything started working properly.
But if I may ask, shouldn't the validator have caught that anyway? While I do realize that it's unlikely that anyone will target my API routes in this way (especially as they will be protected), in the end it still triggered a database call with the invalid body. Shouldn't the ValidationPipe trigger an error if it can't serialize the body properly?
:tada: This issue has been resolved in version 1.8.0-beta.3 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
Hi @mathcrln
Thanks for the report. The fix has been released in the beta
channel. Let me know if it fix your issue as well.
:tada: This issue has been resolved in version 1.8.2 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
Describe the bug A clear and concise description of what the bug is.
Neither the validation of the body nor the transformation with class-transformer seem to work. I have both class-transformer and class-validator installed. Yet, when I make a POST request to the concerned API Route with a body, it is not transformed into the appropriate object from the DTO. Furthermore, no validation is done either. The following code go straight to my prisma upsert method call which, of course reject the entry (even if it's correct) because it has not been parsed.
I am aware that existing issues has been opened in the past related to this same apparent bug: #402, 357. Nevertheless, none of the suggestions offered in these issues seemed to solve my problem.
To Reproduce Steps to reproduce the behavior:
Expected behavior A clear and concise description of what you expected to happen.
I expect for the body to have been parsed following the DTO and for an error to have been thrown before the code reach the Prisma call if the body validation was incorrect.
Additional context Add any other context about the problem here. Here is my tsconfig.json. Don't hesitate if you need any more information.