TaleLin / lin-cms-spring-boot

🔨 基于SpringBoot的CMS/DMS/管理系统开发框架
http://doc.cms.talelin.com/
MIT License
904 stars 253 forks source link

当请求体中的 json 参数类型错误,异常拦截报错不准确 #184

Closed colorful3 closed 3 years ago

colorful3 commented 3 years ago

描述 bug

后端返回的报错为:

{
    "code": 10030,
    "message": "请求体不可为空",
    "request": "PUT /cms/admin/user/2"
}

(截图为”管理员更新用户信息”的接口请求)

image

请求体不可为空的报错信息非常模糊,对前端误导性极强。

你使用哪个版本出现该问题?

如果使用master,请表明是 master 分支,否则给出具体的版本号 master 分支,0.2.0-RC2 版本。

If your bug is deterministic, can you give a minimal reproducing code? Some bugs are not deterministic. Can you describe with precision in which context it happened? If this is possible, can you share your code? 修改如下代码: https://github.com/TaleLin/lin-cms-spring-boot/blob/bd6b0c8692b95bafd14b8ba0585ebb64b35d8788/src/main/java/io/github/talelin/latticy/common/exception/RestExceptionHandler.java#L191-L205

towelong commented 3 years ago

@colorful3 这个字段类型不匹配的问题可以考虑在控制器里面通过@valid 注解进行参数做吗? 这样的话就可以保证返回的错误消息比较准确

towelong commented 3 years ago

@colorful3 image已解决