diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/handler/HighestGlobalExceptionHandler b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/handler/HighestGlobalExceptionHandler new file mode 100644 index 00000000..fcab261e --- /dev/null +++ b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/handler/HighestGlobalExceptionHandler @@ -0,0 +1,31 @@ +package com.ruoyi.common.security.handler; + +import com.ruoyi.common.core.web.domain.AjaxResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import javax.servlet.http.HttpServletRequest; +import java.sql.SQLException; + +/** + * @description 高优先级的异常处理 + * @author Acechengui + * @date Created in 2023-08-29 + */ +@Order(Ordered.HIGHEST_PRECEDENCE) +@RestControllerAdvice +public class HighestGlobalExceptionHandler { + + private static final Logger log = LoggerFactory.getLogger(HighestGlobalExceptionHandler.class); + + @ExceptionHandler(SQLException.class) + public AjaxResult handleSQLException(SQLException e, HttpServletRequest request) { + String requestURI = request.getRequestURI(); + log.error("请求地址'{}',发生脚本执行异常.", requestURI, e); + return AjaxResult.error("发生了数据库异常"); + } +}