AEM Assets (6.5.4) Error Handling for all extensions | Community
Skip to main content
Level 2
September 4, 2020
Solved

AEM Assets (6.5.4) Error Handling for all extensions

  • September 4, 2020
  • 1 reply
  • 1565 views

Hi,

 

We recently set up a custom error page by overlaying /libs/sling/servlet/errorhandler/404.jsp.

 

our 404.html contains:

<html data-sly-use.responseStatus="apps.sling.servlet.errorhandler.ResponseStatus404">

...

</html>

 

and the ResponseStatus404.java file contains this:

public void activate() throws Exception {
getResponse().setStatus(404);
}

 

The error page works fine for URLs with a .html extension (/abc/pqr.html)

But if there is no extension or some other extension like .txt, then it displays the full code of our custom error page but doesn't render the page. I checked in /system/console/requests and saw that our custom error page is indeed being called, but for some reason it doesn't get rendered and instead we see the html code of the error page.

 

Please let me know how I should fix this issue and make the error page work for all extensions/no extension in URL.

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 Andrei_Dantsou

Hello @abinav_98 ,

You should specify the content type in ResponseStatus404.java as well:

public void activate() throws Exception {
getResponse().setStatus(404);
getResponse().setContentType("text/html");
}

 
Regards

1 reply

Andrei_Dantsou
Andrei_DantsouAccepted solution
Level 3
September 4, 2020

Hello @abinav_98 ,

You should specify the content type in ResponseStatus404.java as well:

public void activate() throws Exception {
getResponse().setStatus(404);
getResponse().setContentType("text/html");
}

 
Regards

abinav_98Author
Level 2
September 4, 2020
You sir are a legend. Thank you so much 🙂 . Didn't realize it was such a simple fix.