处理Exception捕获导致客户端无法正常跳转问题

This commit is contained in:
wenc000 2020-06-06 22:01:26 +08:00
parent 1559eff981
commit 9a3fb3e060

View File

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