验证失败(应为数字字符串)



我在nestJS框架中的控制器有问题,有人能告诉我下面出了什么问题吗?启动此控制器后,我有Bad request,我没有;我不知道出了什么问题,我有一个类似的端点,它可以正常工作,但这里不工作;/


@Delete('/remove/:projectId')
@AuthRequired()
async removeProjectGlobally(@CurrentUser() user: User, @Param('projectId', new ParseIntPipe()) projectId: number): Promise<ResponseHandler> {
return await this.projectService.removeProject(projectId, user);
}
Error: Bad Request
Response body
{
"statusCode": 400,
"message": "Validation failed (numeric string is expected)",
"error": "Bad Request"
}

感谢的帮助

该错误消息意味着projectId参数应该是像"123456"这样的数字字符串,而它显然是其他具有非数字字符的字符串。

这是由声明参数的ParseIntPipe()部分强制执行的,该部分将把"123"解码为123,或者如果因为它不是数字而无法解码,则抛出错误。

@Param('projectId', new ParseIntPipe()) projectId: number

很难用更多关于你的请求的信息来提供更多建议,如果你发送的请求的路径像/remove/123456,那么它应该像你期望的那样。