From 501be029c6b64c2b1ccdb04bfab59c273fb37a0f Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期四, 19 九月 2024 17:40:42 +0800 Subject: [PATCH] update 优化 sse 异常单独处理 避免出现异常报错问题 --- ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/handler/GlobalExceptionHandler.java | 25 +++++++++++++++---------- 1 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/handler/GlobalExceptionHandler.java b/ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/handler/GlobalExceptionHandler.java index bd801ba..56c9e9f 100644 --- a/ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/handler/GlobalExceptionHandler.java +++ b/ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/handler/GlobalExceptionHandler.java @@ -9,9 +9,9 @@ import lombok.extern.slf4j.Slf4j; import org.dromara.common.core.domain.R; import org.dromara.common.core.exception.ServiceException; +import org.dromara.common.core.exception.SseException; import org.dromara.common.core.exception.base.BaseException; import org.dromara.common.core.utils.StreamUtils; -import org.dromara.common.core.utils.StringUtils; import org.springframework.context.support.DefaultMessageSourceResolvable; import org.springframework.validation.BindException; import org.springframework.web.HttpRequestMethodNotSupportedException; @@ -56,19 +56,24 @@ } /** + * 璁よ瘉澶辫触 + */ + @ResponseStatus(org.springframework.http.HttpStatus.UNAUTHORIZED) + @ExceptionHandler(SseException.class) + public String handleNotLoginException(SseException e, HttpServletRequest request) { + String requestURI = request.getRequestURI(); + log.error("璇锋眰鍦板潃'{}',璁よ瘉澶辫触'{}',鏃犳硶璁块棶绯荤粺璧勬簮", requestURI, e.getMessage()); + return e.getMessage(); + } + + /** * servlet寮傚父 */ @ExceptionHandler(ServletException.class) public R<Void> handleServletException(ServletException e, HttpServletRequest request) { - if (StringUtils.contains(e.getMessage(), "NotLoginException")) { - String requestURI = request.getRequestURI(); - log.error("璇锋眰鍦板潃'{}',璁よ瘉澶辫触'{}',鏃犳硶璁块棶绯荤粺璧勬簮", requestURI, e.getMessage()); - return R.fail(HttpStatus.HTTP_UNAUTHORIZED, "璁よ瘉澶辫触锛屾棤娉曡闂郴缁熻祫婧�"); - } else { - String requestURI = request.getRequestURI(); - log.error("璇锋眰鍦板潃'{}',鍙戠敓鏈煡寮傚父.", requestURI, e); - return R.fail(e.getMessage()); - } + String requestURI = request.getRequestURI(); + log.error("璇锋眰鍦板潃'{}',鍙戠敓鏈煡寮傚父.", requestURI, e); + return R.fail(e.getMessage()); } /** -- Gitblit v1.9.3