in src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java [274:336]
public void handleError(
final int status,
final String message,
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 status {}({})", status, message);
return;
}
// start tracker
RequestProgressTracker progressTracker = request.getRequestProgressTracker();
String timerName = "handleError:status=" + status;
progressTracker.startTimer(timerName);
final ResourceResolver scriptResolver = this.getScriptResourceResolver();
try {
// find the error handler component
Resource resource = getErrorResource(request);
// find a servlet for the status as the method name
String extension = request.getRequestPathInfo().getExtension();
ResourceCollector locationUtil = new ResourceCollector(
String.valueOf(status),
DEFAULT_ERROR_HANDLER_RESOURCE_TYPE,
resource,
extension,
this.executionPaths.get(),
this.useResourceCaching);
Servlet servlet = getServletInternal(locationUtil, request, scriptResolver);
// fall back to default servlet if none
if (servlet == null) {
servlet = getDefaultErrorServlet(request, resource, scriptResolver);
}
// set the message properties
request.setAttribute(RequestDispatcher.ERROR_STATUS_CODE, status);
request.setAttribute(RequestDispatcher.ERROR_MESSAGE, message);
request.setAttribute(RequestDispatcher.ERROR_METHOD, request.getMethod());
if (request.getQueryString() != null) {
request.setAttribute(RequestDispatcher.ERROR_QUERY_STRING, request.getQueryString());
}
// the servlet name for a sendError handling is still stored
// as the request attribute
Object servletName = request.getAttribute(SLING_CURRENT_SERVLET_NAME);
if (servletName instanceof String) {
request.setAttribute(RequestDispatcher.ERROR_SERVLET_NAME, servletName);
}
// 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");
}
}