{"record":{"id":"97f3f9303448a219","repo":"symfony/http-kernel","slug":"0-error-when-rendering-s-status-code-is-d","errorCode":"0","errorMessage":"Error when rendering \"%s\" (Status code is %d).","messagePattern":"Error when rendering \"(.+?)\" \\(Status code is (.+?)\\)\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"Fragment/FragmentHandler.php","lineNumber":98,"sourceCode":"\n        return $this->deliver($this->renderers[$renderer]->render($uri, $request, $options));\n    }\n\n    /**\n     * Delivers the Response as a string.\n     *\n     * When the Response is a StreamedResponse, the content is streamed immediately\n     * instead of being returned.\n     *\n     * @return string|null The Response content or null when the Response is streamed\n     *\n     * @throws \\RuntimeException when the Response is not successful\n     */\n    protected function deliver(Response $response): ?string\n    {\n        if (!$response->isSuccessful()) {\n            $responseStatusCode = $response->getStatusCode();\n            throw new \\RuntimeException(\\sprintf('Error when rendering \"%s\" (Status code is %d).', $this->requestStack->getCurrentRequest()->getUri(), $responseStatusCode), 0, new HttpException($responseStatusCode));\n        }\n\n        if (!$response instanceof StreamedResponse) {\n            return $response->getContent();\n        }\n\n        $response->sendContent();\n\n        return null;\n    }\n}\n","sourceCodeStart":80,"sourceCodeEnd":110,"githubUrl":"https://github.com/symfony/http-kernel/blob/aa3a39d7286a62cdfea98f0e69c651a3da6e36cf/Fragment/FragmentHandler.php#L80-L110","documentation":"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.","triggerScenarios":"The rendered controller/route returns 404, 500, etc.; render() with ignore_errors=false receives a non-2xx Response from the sub-request.","commonSituations":"Fragment route removed or renamed (404), access-control denying the sub-request (403), an exception inside the fragment controller (500).","solutions":["Inspect the chained previous HttpException to get the status code and fix the fragment endpoint.","Pass ['ignore_errors' => true] in options to return empty content instead of throwing.","Check that the _fragment route exists and is accessible for the current user."],"exampleFix":"// before\n$content = $handler->render($uri, 'inline');\n// after\ntry {\n    $content = $handler->render($uri, 'inline');\n} catch (\\RuntimeException $e) {\n    $status = $e->getPrevious() ? $e->getPrevious()->getStatusCode() : 500;\n    $content = '';\n}","handlingStrategy":"try-catch","validationCode":"// optionally pre-check: the fragment route returns 200\n$response = $client->request('GET', $fragmentUri);","typeGuard":null,"tryCatchPattern":"try { $content = $handler->render($uri, 'inline'); } catch (\\RuntimeException $e) { $status = $e->getPrevious()?->getStatusCode(); // fallback content }","preventionTips":["Use ignore_errors option when content is optional","Monitor fragment endpoints with health checks","Ensure _fragment route is not behind restrictive access control"],"tags":["php","symfony","fragment","http-error"],"backgroundTag":"http-error-response","analyzedSha":"aa3a39d7286a62cdfea98f0e69c651a3da6e36cf","analyzedAt":"2026-09-13T18:03:36.509Z","contentChangedAt":"2026-09-13T18:03:36.509Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}