symfony/http-kernel · error · RuntimeException

0

0

Error message

Error when rendering "%s" (Status code is %d).

What it means

FragmentHandler::deliver() throws RuntimeException when the fragment sub-response is not successful (status outside 2xx). The HTTP status is embedded in the message and chained as a HttpException previous, preserving the original failure.

Solutions

  1. Inspect the chained previous HttpException to get the status code and fix the fragment endpoint.
  2. Pass ['ignore_errors' => true] in options to return empty content instead of throwing.
  3. Check that the _fragment route exists and is accessible for the current user.

Example fix

// before
$content = $handler->render($uri, 'inline');
// after
try {
    $content = $handler->render($uri, 'inline');
} catch (\RuntimeException $e) {
    $status = $e->getPrevious() ? $e->getPrevious()->getStatusCode() : 500;
    $content = '';
}
Defensive patterns

Strategy: try-catch

Validate before calling

// optionally pre-check: the fragment route returns 200
$response = $client->request('GET', $fragmentUri);

Try / catch

try { $content = $handler->render($uri, 'inline'); } catch (\RuntimeException $e) { $status = $e->getPrevious()?->getStatusCode(); // fallback content }

Prevention

When it happens

Trigger: The rendered controller/route returns 404, 500, etc.; render() with ignore_errors=false receives a non-2xx Response from the sub-request.

Common situations: Fragment route removed or renamed (404), access-control denying the sub-request (403), an exception inside the fragment controller (500).

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of symfony/http-kernel@aa3a39d728 (2026-09-13). Data as JSON: /api/errors/97f3f9303448a219. Report an issue: GitHub.

Appendix: source

Thrown at Fragment/FragmentHandler.php:98

        return $this->deliver($this->renderers[$renderer]->render($uri, $request, $options));
    }

    /**
     * Delivers the Response as a string.
     *
     * When the Response is a StreamedResponse, the content is streamed immediately
     * instead of being returned.
     *
     * @return string|null The Response content or null when the Response is streamed
     *
     * @throws \RuntimeException when the Response is not successful
     */
    protected function deliver(Response $response): ?string
    {
        if (!$response->isSuccessful()) {
            $responseStatusCode = $response->getStatusCode();
            throw new \RuntimeException(\sprintf('Error when rendering "%s" (Status code is %d).', $this->requestStack->getCurrentRequest()->getUri(), $responseStatusCode), 0, new HttpException($responseStatusCode));
        }

        if (!$response instanceof StreamedResponse) {
            return $response->getContent();
        }

        $response->sendContent();

        return null;
    }
}

View on GitHub (pinned to aa3a39d728)