yangdamao 3 tháng trước cách đây
mục cha
commit
5ba3858b26

+ 12 - 0
zhongzheng-framework/src/main/java/com/zhongzheng/framework/web/exception/GlobalExceptionHandler.java

@@ -9,6 +9,7 @@ import com.zhongzheng.common.exception.DemoModeException;
 import io.jsonwebtoken.ExpiredJwtException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.dao.DataAccessException;
 import org.springframework.security.access.AccessDeniedException;
 import org.springframework.security.authentication.AccountExpiredException;
 import org.springframework.security.core.userdetails.UsernameNotFoundException;
@@ -19,6 +20,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
 import org.springframework.web.servlet.NoHandlerFoundException;
 
 import javax.validation.ConstraintViolationException;
+import java.sql.SQLException;
 
 /**
  * 全局异常处理器
@@ -52,6 +54,16 @@ public class GlobalExceptionHandler
         return AjaxResult.error(e.getCode(), e.getMessage());
     }
 
+    /**
+     * sql错误
+     */
+    @ExceptionHandler({SQLException.class, DataAccessException.class})
+    public AjaxResult handleAllSqlExceptions(Exception e)
+    {
+        log.error(e.getMessage(), e);
+        return AjaxResult.error(HttpStatus.HTTP_INTERNAL_ERROR, "非法操作,请稍后再试");
+    }
+
     @ExceptionHandler(NoHandlerFoundException.class)
     public AjaxResult handlerNoFoundException(Exception e)
     {