全局异常处理逻辑完善

pull/603/merge
macro 2023-05-13 15:01:25 +08:00
parent 137e1510c9
commit a0d0dd1328
1 changed files with 13 additions and 0 deletions

View File

@ -1,5 +1,6 @@
package com.macro.mall.common.exception;
import cn.hutool.core.util.StrUtil;
import com.macro.mall.common.api.CommonResult;
import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
@ -9,6 +10,8 @@ import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import java.sql.SQLSyntaxErrorException;
/**
*
* Created by macro on 2020/2/27.
@ -52,4 +55,14 @@ public class GlobalExceptionHandler {
}
return CommonResult.validateFailed(message);
}
@ResponseBody
@ExceptionHandler(value = SQLSyntaxErrorException.class)
public CommonResult handleSQLSyntaxErrorException(SQLSyntaxErrorException e) {
String message = e.getMessage();
if (StrUtil.isNotEmpty(message) && message.contains("denied")) {
message = "演示环境暂无修改权限,如需修改数据可本地搭建后台服务!";
}
return CommonResult.failed(message);
}
}