ACS commons Error Page Handling

ACS commons provide a capability to load page related to 404, 500, 405 etc. in case requested page didn’t get find or something went wrong on server.

Let’s try to understand the flow for error page handling using ACS commons.

browser raised a request for home.html page. AEM publish instance or dispatcher cache will return requested page if it is found.

In case page doesn’t exist on both the places either on AEM instance or dispatcher will return 404.html page with the help of ACS commons.

If something went wrong or any 500 error occurred on AEM server will return or 500.htm page with the help of ACS commons

Steps to implement ACS Commons error page handling:

  1. install ACS commons package or include same as pom.xml dependency. Follow this link for more detail.

2. Add errorhandler folder inside apps folder as shown below. Add 404.jsp and default.jsp file to handle error.

3. Add below content to 404.jsp file:

<%@page session="false"%><%
%><%@include file="/apps/acs-commons/components/utilities/errorpagehandler/404.jsp" %>

4. Add below content to 500.jsp file:

<%@page session="false"%><%
%><%@include file="/apps/acs-commons/components/utilities/errorpagehandler/default.jsp" %>

5. Add below dependency to filter.xml file:
/ui.apps/src/main/content/META-INF/vault/filter.xml

6. Add below code to inline pom.xml file:
/ui.apps.structure/pom.xml

7. Add below code snippet in page component dialog xml file to author root site page to author error page.

8. Add below OSGI configuration in code base to enable error page handling.

9. Create below hierarchy to create error pages of type CQ page inside project as shown below.

Naming convention for pages inside error page hierarchy will follow HTTP status error codes.
Examples:
Page Not Found → /errors/404.html
Internal Server Error → /errors/500.html
Forbidden Error → /errors/405.html, etc.

Note: Always to try to create new error page template and component to create pages related to error handling.

10. Author error page path /content/practice/us/en/errors) on root content hierarchy as /content/practice/us/en.

11. Try to access a page in browser which doesn’t exist under /content/practice/us/en hierarchy will load 404 page:

Note: SetDispatcherPassError=0 in dispatcher configuration will allow erring requests to be sent back to AEM.

Imran Khan, Adobe Community Advisor, AEM certified developer and Java Geek, is an experienced AEM developer with over 11 years of expertise in designing and implementing robust web applications. He leverages Adobe Experience Manager, Analytics, and Target to create dynamic digital experiences. Imran possesses extensive expertise in J2EE, Sightly, Struts 2.0, Spring, Hibernate, JPA, React, HTML, jQuery, and JavaScript.

0