AEM Assets (6.5.4) Error Handling for all extensions

abinav_98

04-09-2020

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.

Accepted Solutions (1)

Accepted Solutions (1)

Andrei_Dantsou

04-09-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

Answers (0)