Adobe-Consulting-Services / acs-aem-commons

http://adobe-consulting-services.github.io/acs-aem-commons/
Apache License 2.0
448 stars 596 forks source link

Error page handler prevents exception from being viewed in Edit mode #3365

Open HitmanInWis opened 2 weeks ago

HitmanInWis commented 2 weeks ago

Required Information

Expected Behavior

When in author EDIT mode, the ACS AEM Commons error handler is supposed to let the default AEM handler render internal server errors. See the following code from default.jsp:

    if (ModeUtil.isPreview(slingRequest)) {
        %><cq:include script="/apps/acs-commons/components/utilities/errorpagehandler/preview/errormessage.jsp" /><%
        return;
    } else {
        // In Author and Edit or Design, so allow OOTB WCMDebugFilter to handle the error message display
        return;
    }

Actual Behavior

Because there is a return; in the else statement, the default error handling from /libs/sling/servlet/errorhandler/default.jsp is never reached, resulting in the end user getting a blank page on exception in Edit/Design mode. Removing the return; restores the expected behavior, with the exception stack trace printing to the window.

Steps to Reproduce

Implement the ACS AEM Commons error handling feature per instructions at https://adobe-consulting-services.github.io/acs-aem-commons/features/error-handler/index.html and trigger a RuntimeException for a server request while in author EDIT mode.

HitmanInWis commented 2 weeks ago

For those looking for a workaround, updating my default.jsp to the following code seems to resolve:

    Integer statusCode = (Integer) request.getAttribute(SlingConstants.ERROR_STATUS);
    if (statusCode == null) { statusCode = SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR; }
    WCMMode wcmMode = WCMMode.fromRequest(request);

    if (statusCode < SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR || wcmMode == WCMMode.DISABLED || wcmMode == WCMMode.PREVIEW) {
%><cq:include script="/apps/acs-commons/components/utilities/errorpagehandler/default.jsp" /><%
    } else {
%><cq:include script="/libs/sling/servlet/errorhandler/default.jsp" /><%
    }

Basically just capturing the case that the ACS Commons handler is doing the return that prevents use of the OOTB libs default.jsp and including it myself.