Highlighted

Custom error handler not reflecting error code for 500

Himanshu_Singhal

MVP

29-04-2019

Hi,

I've overridden the OOTB error handler and it works fine for 404 pages.

For 500 error, I've created a Throwable.jsp and inside the calling service class which internally set the response code 500 and include the page

RequestDispatcher dispatcher = request.getRequestDispatcher(path);

response.setStatus(500);

dispatcher.include(new GetRequest(request), response);

return;

Even though I'm setting the 500 error, the page returns 200. And, also, whatever be the content of error page, it's including inside loaded page which is like, it shows headers twice. I believe that 'cos of loading page already has header and another one is coming from error page which is included inside loading page.

Could you please check?

Best regards,
Himanshu Singhal

Replies

Highlighted

antoniom5495929

29-04-2019

Hi Himanshu,

sorry but I think that you are not using the standard way to customize the error handler.

As you can see into the docs [0], you just only need to overlay the errorhandler from default, without using a request dispatcher.

If you want, you can search also for the ACS Common which has inside some develop in order to use a custom error handler.

BTW: in your case I think that the real issue is that you are performing a dispatch so that the page is returned like a success code.

If you don't want to use the default and standard approach (even if I suggest you to use it); I think that you need to use a redirect in order to avoid this issue.

[0]Customizing Pages shown by the Error Handler

Let us know.

Thanks,

Antonio

Highlighted

Himanshu_Singhal

MVP

29-04-2019

Already checked. In my case, from the JSP, I'm invoking service and inside that, trying to include the response.
For 404, it works fine but for 500, if I go with include then it doesn't change response status or otherwise if I go with forward or sendRedirect then it throws "Response already committed".

Highlighted

Himanshu_Singhal

MVP

29-04-2019

Since, you mentioned that it could be 'cos of dispatch that it could be returning success. But, that doesn't happen in case of 404.

Highlighted

Himanshu_Singhal

MVP

29-04-2019

Nope; It's something AEM internal 'cos at multiple places let's say null check is not there so it throws 500 error.

Highlighted

antoniom5495929

29-04-2019

Hi,

If the error that you are facing is "Response already committed" you could try to change the response buffer in order to have the response not committed when you are setting the status.

Try in this way and let me know if it works.

A suggestion: don't change the value of the buffer with an high value because otherwise you can face some performance issues.

Thanks,
Antonio

Highlighted

Himanshu_Singhal

MVP

29-04-2019

Changing the size doesn't help. And, also, tried ACS commons way - with that one also getting the "Response not committed" for 500 error.

Highlighted

antoniom5495929

29-04-2019

Hi,

sorry, could you share with us the real message? Is it "Response not commited" or "Response already committed"?

Thanks,

Antonio