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

This commit is contained in:
郝先瑞 2023-04-22 23:26:01 +08:00
parent 1d0bc1f41e
commit 7ce3fe8e27
2 changed files with 9 additions and 7 deletions

View File

@ -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", "用户请求参数错误"),

View File

@ -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());
}
}
/**