mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-09 20:57:21 +08:00
chore: 优化全局异常配置,状态信息不再显示原生异常错误信息
This commit is contained in:
@@ -54,7 +54,7 @@ public class GlobalExceptionHandler {
|
|||||||
*/
|
*/
|
||||||
@ExceptionHandler(BadRequestException.class)
|
@ExceptionHandler(BadRequestException.class)
|
||||||
public R handleBadRequestException(BadRequestException e, HttpServletRequest request) {
|
public R handleBadRequestException(BadRequestException e, HttpServletRequest request) {
|
||||||
log.warn("请求地址 [{}],自定义验证失败。", request.getRequestURI(), e);
|
log.error("请求地址 [{}],自定义验证失败。", request.getRequestURI(), e);
|
||||||
return R.fail(String.valueOf(HttpStatus.BAD_REQUEST.value()), e.getMessage());
|
return R.fail(String.valueOf(HttpStatus.BAD_REQUEST.value()), e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ public class GlobalExceptionHandler {
|
|||||||
return defaultFail;
|
return defaultFail;
|
||||||
}
|
}
|
||||||
String errorMsg = "请上传小于 %sKB 的文件".formatted(NumberUtil.parseLong(sizeLimit) / 1024);
|
String errorMsg = "请上传小于 %sKB 的文件".formatted(NumberUtil.parseLong(sizeLimit) / 1024);
|
||||||
log.warn("请求地址 [{}],上传文件失败,文件大小超过限制。", request.getRequestURI(), e);
|
log.error("请求地址 [{}],上传文件失败,文件大小超过限制。", request.getRequestURI(), e);
|
||||||
return R.fail(String.valueOf(HttpStatus.BAD_REQUEST.value()), errorMsg);
|
return R.fail(String.valueOf(HttpStatus.BAD_REQUEST.value()), errorMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -45,9 +45,9 @@ public class GlobalSaTokenExceptionHandler {
|
|||||||
public R handleNotLoginException(NotLoginException e, HttpServletRequest request) {
|
public R handleNotLoginException(NotLoginException e, HttpServletRequest request) {
|
||||||
log.error("请求地址 [{}],认证失败,无法访问系统资源。", request.getRequestURI(), e);
|
log.error("请求地址 [{}],认证失败,无法访问系统资源。", request.getRequestURI(), e);
|
||||||
String errorMsg = switch (e.getType()) {
|
String errorMsg = switch (e.getType()) {
|
||||||
case NotLoginException.KICK_OUT -> "您已被踢下线。";
|
case NotLoginException.KICK_OUT -> "您已被踢下线";
|
||||||
case NotLoginException.BE_REPLACED_MESSAGE -> "您已被顶下线。";
|
case NotLoginException.BE_REPLACED_MESSAGE -> "您已被顶下线";
|
||||||
default -> "您的登录状态已过期,请重新登录。";
|
default -> "您的登录状态已过期,请重新登录";
|
||||||
};
|
};
|
||||||
return R.fail(String.valueOf(HttpStatus.UNAUTHORIZED.value()), errorMsg);
|
return R.fail(String.valueOf(HttpStatus.UNAUTHORIZED.value()), errorMsg);
|
||||||
}
|
}
|
||||||
|
@@ -61,6 +61,8 @@ continew-starter.web:
|
|||||||
default-error-code: 1
|
default-error-code: 1
|
||||||
# 自定义失败提示(默认:error)
|
# 自定义失败提示(默认:error)
|
||||||
default-error-msg: error
|
default-error-msg: error
|
||||||
|
# 是否将原生异常错误信息填充到状态信息中
|
||||||
|
origin-exception-using-detail-message: false
|
||||||
|
|
||||||
--- ### 接口文档配置
|
--- ### 接口文档配置
|
||||||
springdoc:
|
springdoc:
|
||||||
|
Reference in New Issue
Block a user