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);
|
ErrorWrapperResponse wrapped = new ErrorWrapperResponse(response);
|
||||||
try {
|
try {
|
||||||
chain.doFilter(request, wrapped);
|
chain.doFilter(request, wrapped);
|
||||||
int status = wrapped.getStatus();
|
if (wrapped.hasErrorToSend()) {
|
||||||
if (status >= 400) {
|
handleErrorStatus(request, response, wrapped.getStatus(),
|
||||||
handleErrorStatus(request, response, status, wrapped.getMessage());
|
wrapped.getMessage());
|
||||||
response.flushBuffer();
|
response.flushBuffer();
|
||||||
}
|
}
|
||||||
else if (!request.isAsyncStarted() && !response.isCommitted()) {
|
else if (!request.isAsyncStarted() && !response.isCommitted()) {
|
||||||
|
|
@ -140,7 +140,6 @@ public class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContaine
|
||||||
handleCommittedResponse(request, null);
|
handleCommittedResponse(request, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String errorPath = getErrorPath(this.statuses, status);
|
String errorPath = getErrorPath(this.statuses, status);
|
||||||
if (errorPath == null) {
|
if (errorPath == null) {
|
||||||
response.sendError(status, message);
|
response.sendError(status, message);
|
||||||
|
|
@ -321,6 +320,10 @@ public class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContaine
|
||||||
return this.message;
|
return this.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasErrorToSend() {
|
||||||
|
return this.hasErrorToSend;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue