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());