AEM Cloud Service - Authorable Error Pages and Dispatcher Error Directives

Goal

AEM 2023.3.11382.20230315T073850Z

For showing Custom Error Pages on Publish, say for a 404, you can follow product documentation and create the page in /apps/sling/servlet/errorhandler. However if you want to give some flexibility to the authoring team for some creative error pages, basically Authorable Error Pages, they can be created as normal pages and published. With some Dispatcher Configuration they can be served as Error Pages

Demo | Package Install | Github


Solution

1) Create a sample project to test the Dispatcher Error Directives..

mvn -B org.apache.maven.plugins:maven-archetype-plugin:3.2.1:generate -D archetypeGroupId=com.adobe.aem -D archetypeArtifactId=aem-project-archetype -D archetypeVersion=36 -D aemVersion="cloud" -D appTitle="Experience AEM Dispatcher Error Directives" -D appId="eaem-dispatcher-error-directives" -D groupId="apps.experienceaem.sites" -D frontendModule=none -D includeExamples=n -D includeDispatcherConfig=y 


2) Create a regular page in AEM (may be in a specialized structure like /content/eaem-dispatcher-error-directives/us/en/tools) for showing errors like 404 Not Found, publish them..


3) Copy eaem-dispatcher-error-directives\dispatcher\src\conf.d\available_vhosts\default.vhost and create eaem-dispatcher-error-directives\dispatcher\src\conf.d\available_vhosts\eaem.vhost 


4) Set DispatcherPassError to 1, so the Error Codes are returned by AEM Publish

# Default setting to allow all errors to come from the aem instance
DispatcherPassError 1


5) Set the Error Directives to point to pages created in AEM eg. for 404 below 


ErrorDocument 404 /content/eaem-dispatcher-error-directives/us/en/tools/404.html


6) Create a symlink eaem-dispatcher-error-directives\dispatcher\src\conf.d\enabled_vhosts\eaem.vhost pointing to eaem-dispatcher-error-directives\dispatcher\src\conf.d\available_vhosts\eaem.vhost using the following command (windows)


mklink eaem.vhost "../available_vhosts/eaem.vhost"


7) With the above configuration any 404's from Publish are served with content from page /content/eaem-dispatcher-error-directives/us/en/tools/404.html

No comments:

Post a Comment