Only handle status errors when sendError is called
Update ErrorPageFilter to only handle errors when `response.sendError` has been called. This should allow custom @ExceptionHandlers to completely handle errors and return custom status codes without triggering the "Cannot forward to error page" log message. The Javadoc for sendError states: "The server defaults to creating the response to look like an HTML-formatted server error page containing the specified message" Where as setStatus states "This method is used to set the return status code when there is no error " Fixes gh-2745
This commit is contained in:
parent
5f250ebbc1
commit
de48223a2e
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue