Explorar o código

全局异常处理逻辑完善

macro hai 1 ano
pai
achega
a0d0dd1328

+ 13 - 0
mall-common/src/main/java/com/macro/mall/common/exception/GlobalExceptionHandler.java

@@ -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);
+    }
 }