Custom Error Handler Pages | AEM

To set up custom error handlers in the Adobe Experience Manager to render different HTTP errors, copy the custom script from /libs/sling/servlet/errorhandler to the same location under /apps.

Description description


Adobe Experience Manager


How to create custom scripts or error handlers that render different HTTP errors?

Resolution resolution

The default error handler scripts are located under /libs/sling/servlet/errorhandler.

You can overlay default error handling by copying the script you would like to customize from /libs/sling/servlet/errorhandler to the same location under /apps (i.e. /apps/sling/servlet/errorhandler). Create this path if it does not exist (it doesn’t by default).

For example you can customize the handing of 404 errors by copying /libs/sling/servlet/errorhandler/404.jsp to /apps/sling/servlet/errorhandler/404.jsp

The http 500 errors are caused by server side exceptions. When request processing results in an exception the Apache Sling framework CQ is based on logs the exception and returns http error code 500 and the exception stack trace in the body of the response.

To handle 500 errors the file name of an error handler script must be the same as the exception class (or it’s superclass). So, for example, to handle all exceptions create a script /apps/sling/servlet/errorhandler/Throwable.jsp.

Please refer to Sling error handling for additional information.

Note: The 500.jsp is taken only if HttpServletResponse.sendError(500) is executed explicitly, i.e. from an exception catcher.Otherwise only the response code is set to 500, but the 500.jsp is not executed. In this case you can add an  Exception.jsp  to handle all this exceptions.

Note: On an author instance the CQ WCM Debug Filter is enabled by default. This leads always to a response code 200 and the default Errorhandler is taken which writes the full stack trace to the response. On a publish instance the CQ WCM Debug Filter is always disabled (also if you configure it to be enabled).