Expand my Community achievements bar.

SOLVED

AEM Assets (6.5.4) Error Handling for all extensions

Avatar

Level 1

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.

1 Accepted Solution

Avatar

Correct answer by
Level 4

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

View solution in original post

2 Replies

Avatar

Correct answer by
Level 4

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

Avatar

Level 1
You sir are a legend. Thank you so much . Didn't realize it was such a simple fix.