From 80d1e28d0f5b643a753a2989dbba4e123b9ad87d Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期二, 10 五月 2022 14:42:02 +0800 Subject: [PATCH] update springboot-admin 2.6.6 => 2.6.7 update springboot-mybatis 2.2.0 => 2.2.2 update sa-token 1.29.0 => 1.30.0 update hutool 5.7.22 => 5.8.0 update druid 1.2.8 => 1.2.9 update tlog 1.3.6 => 1.4.0 --- ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java | 27 +++++++++++++++++++++++++++ 1 files changed, 27 insertions(+), 0 deletions(-) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java index 90b265e..326c96a 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java @@ -9,7 +9,9 @@ import com.ruoyi.common.exception.DemoModeException; import com.ruoyi.common.exception.ServiceException; import lombok.extern.slf4j.Slf4j; +import org.mybatis.spring.MyBatisSystemException; import org.springframework.context.support.DefaultMessageSourceResolvable; +import org.springframework.dao.DuplicateKeyException; import org.springframework.validation.BindException; import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.MethodArgumentNotValidException; @@ -72,6 +74,31 @@ } /** + * 涓婚敭鎴朥NIQUE绱㈠紩锛屾暟鎹噸澶嶅紓甯� + */ + @ExceptionHandler(DuplicateKeyException.class) + public R<Void> handleDuplicateKeyException(DuplicateKeyException e, HttpServletRequest request) { + String requestURI = request.getRequestURI(); + log.error("璇锋眰鍦板潃'{}',鏁版嵁搴撲腑宸插瓨鍦ㄨ褰�'{}'", requestURI, e.getMessage()); + return R.fail("鏁版嵁搴撲腑宸插瓨鍦ㄨ璁板綍锛岃鑱旂郴绠$悊鍛樼‘璁�"); + } + + /** + * Mybatis绯荤粺寮傚父 閫氱敤澶勭悊 + */ + @ExceptionHandler(MyBatisSystemException.class) + public R<Void> handleCannotFindDataSourceException(MyBatisSystemException e, HttpServletRequest request) { + String requestURI = request.getRequestURI(); + String message = e.getMessage(); + if (message.contains("CannotFindDataSourceException")) { + log.error("璇锋眰鍦板潃'{}', 鏈壘鍒版暟鎹簮", requestURI); + return R.fail("鏈壘鍒版暟鎹簮锛岃鑱旂郴绠$悊鍛樼‘璁�"); + } + log.error("璇锋眰鍦板潃'{}', Mybatis绯荤粺寮傚父", requestURI, e); + return R.fail(message); + } + + /** * 涓氬姟寮傚父 */ @ExceptionHandler(ServiceException.class) -- Gitblit v1.9.3