Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

AEM Assets (6.5.4) Error Handling for all extensions

abinav_98
Level 1
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
Andrei_Dantsou
Correct answer by
Level 4
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
Andrei_Dantsou
Correct answer by
Level 4
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

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