in src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java [340:388]
public void handleError(final Throwable throwable, final SlingHttpServletRequest request, final SlingHttpServletResponse response)
throws IOException {
// do not handle, if already handling ....
if (request.getAttribute(SlingConstants.ERROR_REQUEST_URI) != null) {
LOGGER.error("handleError: Recursive invocation. Not further handling Throwable:", throwable);
return;
}
// start tracker
RequestProgressTracker progressTracker = request.getRequestProgressTracker();
String timerName = "handleError:throwable=" + throwable.getClass().getName();
progressTracker.startTimer(timerName);
final ResourceResolver scriptResolver = this.getScriptResourceResolver();
try {
// find the error handler component
Servlet servlet = null;
Resource resource = getErrorResource(request);
Class<?> tClass = throwable.getClass();
while (servlet == null && tClass != Object.class) {
// find a servlet for the simple class name as the method name
String extension = request.getRequestPathInfo().getExtension();
ResourceCollector locationUtil = new ResourceCollector(tClass.getSimpleName(),
DEFAULT_ERROR_HANDLER_RESOURCE_TYPE, resource,
extension, this.executionPaths.get(), this.useResourceCaching);
servlet = getServletInternal(locationUtil, request, scriptResolver);
// go to the base class
tClass = tClass.getSuperclass();
}
if (servlet == null) {
servlet = getDefaultErrorServlet(request, resource, scriptResolver);
}
// set the message properties
request.setAttribute(SlingConstants.ERROR_EXCEPTION, throwable);
request.setAttribute(SlingConstants.ERROR_EXCEPTION_TYPE, throwable.getClass());
request.setAttribute(SlingConstants.ERROR_MESSAGE, throwable.getMessage());
// log a track entry after resolution before calling the handler
progressTracker.logTimer(timerName, "Using handler {0}", RequestUtil.getServletName(servlet));
handleError(servlet, request, response);
} finally {
progressTracker.logTimer(timerName, "Error handler finished");
}
}