[MAGNOLIA-6443] RequestDispatchUtil swallows any exception at forward Created: 16/Nov/15  Updated: 19/May/22  Resolved: 19/May/22

Status: Closed
Project: Magnolia
Component/s: None
Affects Version/s: 5.4.1, 5.4.3
Fix Version/s: None

Type: Bug Priority: Critical
Reporter: Fabrizio Giustina Assignee: Unassigned
Resolution: Won't Do Votes: 0
Labels: papercut
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Template:
Patch included:
Yes
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 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)



 Comments   
Comment by Roman Kovařík [ 19/May/22 ]

Hello,

This ticket is now marked as closed due to one of the following reasons:

  • A long period of inactivity
  • Uses an old or Beta version of an application, module, or framework that we no longer support
  • The issue is no longer reproducible or has been fixed in later versions

If you are still facing a problem or consider this issue still relevant, please feel free to re-open the ticket and we will reach out to you.

Thank you,
The Magnolia Team

Generated at Mon Feb 12 04:14:34 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.