update snowy-web-app/src/main/java/vip/xiaonuo/core/config/GlobalConfigure.java.

【修复】Satoken异常,解决返回结果data字段为字符串“null”的问题

Signed-off-by: bubu <8096927+bubu-space@user.noreply.gitee.com>
pull/251/head
bubu 2025-04-07 15:38:11 +00:00 committed by Gitee
parent e8ee651e5c
commit 341bf964eb
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 4 additions and 1 deletions

View File

@ -279,7 +279,10 @@ public class GlobalConfigure implements WebMvcConfigurer {
// 在[异常处理函数]里的返回值将作为字符串输出到前端此处统一转为JSON输出前端
SaResponse saResponse = SaHolder.getResponse();
saResponse.setHeader(Header.CONTENT_TYPE.getValue(), ContentType.JSON + ";charset=" + CharsetUtil.UTF_8);
return GlobalExceptionUtil.getCommonResult((Exception) e);
// result是字符串需要手动转为json格式。全局异常处理中的字符串返回信息ommonResult<String>)已经被@ResponseBody进行json格式化了
CommonResult<String> result = GlobalExceptionUtil.getCommonResult((Exception) e);
Gson g = new GsonBuilder().serializeNulls().create();
return g.toJson(result);
});
}