From 27e7299964b861c079dbb2826edab00dfd6dc27d Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期四, 12 九月 2024 17:30:27 +0800
Subject: [PATCH] Merge branch 'master' of ssh://172.16.8.100:29418/iailab-plat

---
 iailab-framework/iailab-common-web/src/main/java/com/iailab/framework/web/core/handler/GlobalExceptionHandler.java |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/iailab-framework/iailab-common-web/src/main/java/com/iailab/framework/web/core/handler/GlobalExceptionHandler.java b/iailab-framework/iailab-common-web/src/main/java/com/iailab/framework/web/core/handler/GlobalExceptionHandler.java
index 958589c..79930b8 100644
--- a/iailab-framework/iailab-common-web/src/main/java/com/iailab/framework/web/core/handler/GlobalExceptionHandler.java
+++ b/iailab-framework/iailab-common-web/src/main/java/com/iailab/framework/web/core/handler/GlobalExceptionHandler.java
@@ -25,6 +25,7 @@
 import org.springframework.web.bind.annotation.RestControllerAdvice;
 import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
 import org.springframework.web.servlet.NoHandlerFoundException;
+import org.springframework.dao.DuplicateKeyException;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.validation.ConstraintViolation;
@@ -94,6 +95,9 @@
         }
         if (ex instanceof AccessDeniedException) {
             return accessDeniedExceptionHandler(request, (AccessDeniedException) ex);
+        }
+        if (ex instanceof DuplicateKeyException) {
+            return duplicateKeyExceptionHandler((DuplicateKeyException) ex);
         }
         return defaultExceptionHandler(request, ex);
     }
@@ -199,6 +203,17 @@
     }
 
     /**
+     * 处理业务异常 SQLIntegrityConstraintViolationException
+     *
+     * 数据库存在重复数据
+     */
+    @ExceptionHandler(value = DuplicateKeyException.class)
+    public CommonResult<?> duplicateKeyExceptionHandler(DuplicateKeyException ex) {
+        log.warn("[duplicateKeyExceptionHandler]", ex);
+        return CommonResult.error(DATA_REPETITION.getCode(), DATA_REPETITION.getMsg());
+    }
+
+    /**
      * 处理业务异常 ServiceException
      *
      * 例如说,商品库存不足,用户手机号已存在。

--
Gitblit v1.9.3