From 54f04bcde3613ee5ce511b1b0d59c0ffe12f5081 Mon Sep 17 00:00:00 2001 From: wanggeng <450292408@qq.com> Date: Wed, 8 Dec 2021 17:08:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E6=B6=88exception=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E6=8D=95=E8=8E=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wgink/common/advice/ResponseAdvice.java | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/common/src/main/java/ink/wgink/common/advice/ResponseAdvice.java b/common/src/main/java/ink/wgink/common/advice/ResponseAdvice.java index cf5668a9..ec995ac3 100644 --- a/common/src/main/java/ink/wgink/common/advice/ResponseAdvice.java +++ b/common/src/main/java/ink/wgink/common/advice/ResponseAdvice.java @@ -14,7 +14,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; -import org.springframework.security.authentication.InsufficientAuthenticationException; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; @@ -42,11 +41,8 @@ public class ResponseAdvice { private static final Logger LOG = LoggerFactory.getLogger(ResponseAdvice.class); @ResponseBody - @ExceptionHandler({SystemException.class, SQLSyntaxErrorException.class, Exception.class, HashMapUtil.TypeConversionException.class, ReflectUtil.ReflectException.class}) - public void responseException(HttpServletRequest request, HttpServletResponse response, Exception e) throws IOException { - if (e instanceof InsufficientAuthenticationException) { - throw new InsufficientAuthenticationException(e.getMessage()); - } + @ExceptionHandler({SystemException.class, SQLSyntaxErrorException.class, HashMapUtil.TypeConversionException.class, ReflectUtil.ReflectException.class}) + public void responseException(HttpServletRequest request, HttpServletResponse response, Exception e) throws IOException, ServletException { if (e instanceof FileException) { LOG.error(e.getMessage()); } else if (e instanceof ParamsException) { @@ -115,16 +111,11 @@ public class ResponseAdvice { if (!response.isCommitted()) { StackTraceElement[] stackTraces = e.getStackTrace(); List errorStackTraces = new ArrayList(); - for(StackTraceElement stackTraceElement: stackTraces) { + for (StackTraceElement stackTraceElement : stackTraces) { errorStackTraces.add(stackTraceElement.toString()); } - try { - request.getSession().setAttribute("errorStackTraces", errorStackTraces); - request.getRequestDispatcher("/error/exception").forward(request, response); - } catch (IOException | ServletException ioException) { - ioException.printStackTrace(); - } - return; + request.getSession().setAttribute("errorStackTraces", errorStackTraces); + request.getRequestDispatcher("/error/exception").forward(request, response); } } }