SlingHttpServletResponse setStatus and dispatcher forward not working for 500 on cloud | Community
Skip to main content
Level 2
March 29, 2023
Solved

SlingHttpServletResponse setStatus and dispatcher forward not working for 500 on cloud

  • March 29, 2023
  • 1 reply
  • 762 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by joerghoh

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").

 

1 reply

joerghoh
Adobe Employee
joerghohAdobe EmployeeAccepted solution
Adobe Employee
March 31, 2023

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").