private void handleError()

in src/main/java/org/apache/sling/servlets/resolver/internal/SlingServletResolver.java [667:709]


    private void handleError(
            final Servlet errorHandler,
            final SlingJakartaHttpServletRequest request,
            final SlingJakartaHttpServletResponse response)
            throws IOException {

        request.setAttribute(RequestDispatcher.ERROR_REQUEST_URI, request.getRequestURI());

        // if there is no explicitly known error causing servlet, use
        // the name of the error handler servlet
        if (request.getAttribute(RequestDispatcher.ERROR_SERVLET_NAME) == null) {
            request.setAttribute(
                    RequestDispatcher.ERROR_SERVLET_NAME,
                    errorHandler.getServletConfig().getServletName());
        }

        // Let the error handler servlet process the request and
        // forward all exceptions if it fails.
        // Before SLING-4143 we only forwarded IOExceptions.
        try {
            // SLING-10478 - wrap the response to track if the writer is still open
            // after the errorHandler has serviced the request
            HandleErrorSlingHttpServletResponse wrappedResponse = new HandleErrorSlingHttpServletResponse(response);

            errorHandler.service(request, wrappedResponse);

            // SLING-10478 - if the response writer has not already been closed, then flush and close it
            if (wrappedResponse.isOpen()) {
                // commit the response
                wrappedResponse.flushBuffer();
                // close the response (SLING-2724)
                wrappedResponse.getWriter().close();
            }
        } catch (final Throwable t) { // NOSONAR
            LOGGER.error("Calling the error handler resulted in an error", t);
            LOGGER.error("Original error " + request.getAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE), (Throwable)
                    request.getAttribute(RequestDispatcher.ERROR_EXCEPTION));
            final IOException x =
                    new IOException("Error handler failed: " + t.getClass().getName());
            x.initCause(t);
            throw x;
        }
    }