提交 7ce3fe8e 编写于 作者: 郝先瑞

refactor: 优化线上数据库无权操作权限提示

上级 1d0bc1f4
......@@ -30,7 +30,7 @@ public enum ResultCode implements IResultCode, Serializable {
AUTHORIZED_ERROR("A0300", "访问权限异常"),
ACCESS_UNAUTHORIZED("A0301", "访问未授权"),
FORBIDDEN_OPERATION("A0302", "演示环境禁止修改、删除重要数据,请本地部署后测试"),
FORBIDDEN_OPERATION("A0302", "演示环境禁止新增、修改和删除重要数据,请本地部署后测试"),
PARAM_ERROR("A0400", "用户请求参数错误"),
......
......@@ -144,9 +144,6 @@ public class GlobalExceptionHandler {
return Result.failed(errorMessage);
}
/**
* TypeMismatchException
*/
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(TypeMismatchException.class)
public <T> Result<T> processException(TypeMismatchException e) {
......@@ -160,7 +157,7 @@ public class GlobalExceptionHandler {
String errorMsg = e.getMessage();
log.error(errorMsg);
if (StrUtil.isNotBlank(errorMsg) && errorMsg.contains("denied to user")) {
return Result.failed("数据库用户无操作权限,建议本地搭建数据库环境");
return Result.failed(ResultCode.FORBIDDEN_OPERATION);
} else {
return Result.failed(e.getMessage());
}
......@@ -195,8 +192,13 @@ public class GlobalExceptionHandler {
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(Exception.class)
public <T> Result<T> handleException(Exception e) {
log.error("unknown exception:{}", e.getMessage());
return Result.failed(e.getMessage());
String errorMsg = e.getMessage();
if (StrUtil.isNotBlank(errorMsg) && errorMsg.contains("denied to user")) {
return Result.failed(ResultCode.FORBIDDEN_OPERATION);
}else{
log.error("unknown exception:{}", e.getMessage());
return Result.failed(e.getMessage());
}
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册