Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

SlingHttpServletResponse setStatus and dispatcher forward not working for 500 on cloud

Avatar

Level 2

From sling filter, in case of an error we are trying to send back the response code to the browser using SlingHttpServletResponse setStatus method and then forward to error page using RequestDispatcher. Please see the code below for the same -

slingResponse.setStatus(errorCode);
RequestDispatcher dispatch = slingRequest.getRequestDispatcher(redirectURLForErrorPage);
dispatch.forward(slingRequest, slingResponse);

This is working fine if the errorCode is in series of 400 i.e. 401, 404 etc. but its not working for errorCode 500.
If the errorCode is 500, it sends back the 500 error code to browser but does not forward to the error page.

The same code works fine on local for both 400s and 500s error codes but does not work on the cloud environments.

We have tried using dispatch.include and setting larger buffer size, as suggested in some other posts in this community, but that didnt work.

Is this something that is blocked by some dispatcher config in cloud or some other issue, please suggest.

Thanks in advance.

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

You should not need to do this manually. The Sling Main Servlet catches all exceptions and forwards them to a configured error handler. See https://sling.apache.org/documentation/the-sling-engine/errorhandling.html (especially the section "Default Handlers").

 

View solution in original post

1 Reply

Avatar

Correct answer by
Employee Advisor

You should not need to do this manually. The Sling Main Servlet catches all exceptions and forwards them to a configured error handler. See https://sling.apache.org/documentation/the-sling-engine/errorhandling.html (especially the section "Default Handlers").