取消exception全局捕获

This commit is contained in:
wanggeng 2021-12-08 17:08:14 +08:00
parent ab6cf6661a
commit 54f04bcde3

View File

@ -14,7 +14,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.security.authentication.InsufficientAuthenticationException;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
@ -42,11 +41,8 @@ public class ResponseAdvice {
private static final Logger LOG = LoggerFactory.getLogger(ResponseAdvice.class); private static final Logger LOG = LoggerFactory.getLogger(ResponseAdvice.class);
@ResponseBody @ResponseBody
@ExceptionHandler({SystemException.class, SQLSyntaxErrorException.class, Exception.class, HashMapUtil.TypeConversionException.class, ReflectUtil.ReflectException.class}) @ExceptionHandler({SystemException.class, SQLSyntaxErrorException.class, HashMapUtil.TypeConversionException.class, ReflectUtil.ReflectException.class})
public void responseException(HttpServletRequest request, HttpServletResponse response, Exception e) throws IOException { public void responseException(HttpServletRequest request, HttpServletResponse response, Exception e) throws IOException, ServletException {
if (e instanceof InsufficientAuthenticationException) {
throw new InsufficientAuthenticationException(e.getMessage());
}
if (e instanceof FileException) { if (e instanceof FileException) {
LOG.error(e.getMessage()); LOG.error(e.getMessage());
} else if (e instanceof ParamsException) { } else if (e instanceof ParamsException) {
@ -115,16 +111,11 @@ public class ResponseAdvice {
if (!response.isCommitted()) { if (!response.isCommitted()) {
StackTraceElement[] stackTraces = e.getStackTrace(); StackTraceElement[] stackTraces = e.getStackTrace();
List<String> errorStackTraces = new ArrayList(); List<String> errorStackTraces = new ArrayList();
for(StackTraceElement stackTraceElement: stackTraces) { for (StackTraceElement stackTraceElement : stackTraces) {
errorStackTraces.add(stackTraceElement.toString()); errorStackTraces.add(stackTraceElement.toString());
} }
try {
request.getSession().setAttribute("errorStackTraces", errorStackTraces); request.getSession().setAttribute("errorStackTraces", errorStackTraces);
request.getRequestDispatcher("/error/exception").forward(request, response); request.getRequestDispatcher("/error/exception").forward(request, response);
} catch (IOException | ServletException ioException) {
ioException.printStackTrace();
}
return;
} }
} }
} }