diff --git a/spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java b/spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java index c772c3ba2ac..2c247507c66 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java @@ -114,9 +114,9 @@ public class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContaine ErrorWrapperResponse wrapped = new ErrorWrapperResponse(response); try { chain.doFilter(request, wrapped); - int status = wrapped.getStatus(); - if (status >= 400) { - handleErrorStatus(request, response, status, wrapped.getMessage()); + if (wrapped.hasErrorToSend()) { + handleErrorStatus(request, response, wrapped.getStatus(), + wrapped.getMessage()); response.flushBuffer(); } else if (!request.isAsyncStarted() && !response.isCommitted()) { @@ -140,7 +140,6 @@ public class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContaine handleCommittedResponse(request, null); return; } - String errorPath = getErrorPath(this.statuses, status); if (errorPath == null) { response.sendError(status, message); @@ -321,6 +320,10 @@ public class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContaine return this.message; } + public boolean hasErrorToSend() { + return this.hasErrorToSend; + } + } }