in src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java [339:398]
public void handleError(
final Throwable throwable,
final SlingJakartaHttpServletRequest request,
final SlingJakartaHttpServletResponse response)
throws IOException {
// do not handle, if already handling ....
if (request.getAttribute(RequestDispatcher.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(RequestDispatcher.ERROR_EXCEPTION, throwable);
request.setAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE, throwable.getClass());
request.setAttribute(RequestDispatcher.ERROR_MESSAGE, throwable.getMessage());
request.setAttribute(RequestDispatcher.ERROR_METHOD, request.getMethod());
if (request.getQueryString() != null) {
request.setAttribute(RequestDispatcher.ERROR_QUERY_STRING, request.getQueryString());
}
// 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");
}
}