How can I create custom scripts or error handlers that render different HTTP errors?
The default error handler scripts are located under
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/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
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
Please refer to the following documentation for additional information about Sling error handling. http://sling.apache.org/site/errorhandling.html
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)…