From 9a3fb3e06047a259f56db97de1f2948655e82764 Mon Sep 17 00:00:00 2001 From: wenc000 <450292408@qq.com> Date: Sat, 6 Jun 2020 22:01:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86Exception=E6=8D=95=E8=8E=B7?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E5=AE=A2=E6=88=B7=E7=AB=AF=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=AD=A3=E5=B8=B8=E8=B7=B3=E8=BD=AC=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/cm/common/advice/ResponseAdvice.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cloud-common/src/main/java/com/cm/common/advice/ResponseAdvice.java b/cloud-common/src/main/java/com/cm/common/advice/ResponseAdvice.java index e40362d..b53b59b 100644 --- a/cloud-common/src/main/java/com/cm/common/advice/ResponseAdvice.java +++ b/cloud-common/src/main/java/com/cm/common/advice/ResponseAdvice.java @@ -10,6 +10,8 @@ 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.security.core.AuthenticationException; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; @@ -36,6 +38,9 @@ public class ResponseAdvice { @ExceptionHandler({SystemException.class, SQLSyntaxErrorException.class, Exception.class}) public void responseException(HttpServletRequest request, HttpServletResponse response, Exception e) throws IOException { LOG.error(e.getMessage(), e); + if (e instanceof InsufficientAuthenticationException) { + throw new InsufficientAuthenticationException(e.getMessage()); + } ErrorResult result = new ErrorResult(ErrorResultCodeEnum.SYSTEM_ERROR.getValue(), "系统错误"); if (e instanceof SaveException) { result.setCode(ErrorResultCodeEnum.SAVE_ERROR.getValue());