Details
-
Bug
-
Resolution: Won't Do
-
Critical
-
None
-
5.4.1, 5.4.3
-
None
Description
use case: in any page reached through a virtualuri where you may have an error... the error is logged but the result for the user is always a blank page, the error page is never shown and there is no way to handle that error as expected.
This is due to the way RequestDispatchUtil handles exceptions after forwards:
if (targetUri.startsWith(FORWARD_PREFIX)) {
String forwardUrl = StringUtils.substringAfter(targetUri, FORWARD_PREFIX);
try {
request.getRequestDispatcher(forwardUrl).forward(request, response);
} catch (Exception e) {
log.error("Failed to forward to {} - {}:{}", forwardUrl, ClassUtils.getShortClassName(e.getClass()), e.getMessage());
}
return true;
}
As you can see there is a "catch Exception" which logs and ignores, just returning true like for successful requests.
I would propose to change the catch by simply rethrowing runtime exceptions, e.g.
if (targetUri.startsWith(FORWARD_PREFIX))
{
String forwardUrl = StringUtils.substringAfter(targetUri, FORWARD_PREFIX);
try
{
request.getRequestDispatcher(forwardUrl).forward(request, response);
}
catch (RuntimeException e)
{
log.error("Failed to forward to {} - {}:{}", new Object[]
{ forwardUrl, ClassUtils.getShortClassName(e.getClass()), e.getMessage() });
throw e;
}
catch (Exception e)
{
log.error("Failed to forward to {} - {}:{}", new Object[]
{ forwardUrl, ClassUtils.getShortClassName(e.getClass()), e.getMessage() });
throw new RuntimeException(e);
}
return true;
}
with this patch the error page is properly displayed (or the exception can be handled in other ways if needed)
Checklists
Acceptance criteria