Nestjs validation failed (numeric string is expected). Nov 30, 2019 · The reason fo...
Nestjs validation failed (numeric string is expected). Nov 30, 2019 · The reason for this error is that I had some dynamic routes that have ParseInt directives on them like /users/:id. If you remove the ParseInt directives, the routes work fine. This typically occurs when incoming JSON payloads or URL query parameters supply numeric values as strings (e. So in short, the only thing that matters in route selection, is pattern, not validation set in it. Validation occurs later on. benutzerService. g. Apr 26, 2020 · Currently right now if I call the endpoint without the limit query argument, the built in ParseIntPipe will throw a BadRequestException and return a bad request response to the user with the message Validation failed (numeric string is expected) . Simple solution – use @Type() decorator from class-transformer library, and declare numeric field as Number. This is how it goes. Apr 12, 2021 · Each query parameter comes as string, so it's not possible to validate numeric params correctly. This ordering is really important, as you'll face same exact issue in all major http framework with a router. Mar 23, 2026 · It happens in every http framework with a router. Nov 25, 2020 · With that request you are calling this. This is how express is implemented and NestJS follows the same behaviour: expressjs/express#2235, nestjs/nest#995 Sep 28, 2020 · So, if a validation for ParseIntPipe is failed, please return the passed message property back to the User. findBenutzerByID(id); with the following string: vorgesetzter?istVorgesetzter=true receiving the error you describe. To fix this issue, I had to create a custom extension for ValidationPipe and use that instead of the plain validation pipe. Nov 10, 2025 · A common challenge in NestJS DTO validation is the failure of string-to-number conversion when using the standard ValidationPipe({ transform: true }). . , "123"). gkuon9hebcuahvollgnuyl9txl0paly1p5xzh6qdye5nn3ed2ubqrbtv5nhpayuoyn6w2nlea16k7gups35t7pk0vvggsrwc90hor8