{"record":{"id":"d8d3084ae4c0bed3","repo":"symfony/http-kernel","slug":"error-when-rendering-s-status-code-is-d","errorCode":null,"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":"HttpCache/AbstractSurrogate.php","lineNumber":79,"sourceCode":"    {\n        if (!$control = $response->headers->get('Surrogate-Control')) {\n            return false;\n        }\n\n        $pattern = \\sprintf('#content=\"[^\"]*%s/1.0[^\"]*\"#', strtoupper($this->getName()));\n\n        return (bool) preg_match($pattern, $control);\n    }\n\n    public function handle(HttpCache $cache, string $uri, string $alt, bool $ignoreErrors): string\n    {\n        $subRequest = Request::create($uri, 'GET', [], $cache->getRequest()->cookies->all(), [], $cache->getRequest()->server->all());\n\n        try {\n            $response = $cache->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true);\n\n            if (!$response->isSuccessful() && Response::HTTP_NOT_MODIFIED !== $response->getStatusCode()) {\n                throw new \\RuntimeException(\\sprintf('Error when rendering \"%s\" (Status code is %d).', $subRequest->getUri(), $response->getStatusCode()));\n            }\n\n            return $response->getContent();\n        } catch (\\Exception $e) {\n            if ($alt) {\n                return $this->handle($cache, $alt, '', $ignoreErrors);\n            }\n\n            if (!$ignoreErrors) {\n                throw $e;\n            }\n        }\n\n        return '';\n    }\n\n    /**\n     * Remove the Surrogate from the Surrogate-Control header.","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/symfony/http-kernel/blob/aa3a39d7286a62cdfea98f0e69c651a3da6e36cf/HttpCache/AbstractSurrogate.php#L61-L97","documentation":"AbstractSurrogate::handle() throws RuntimeException when the surrogate sub-request response is neither successful nor 304 Not Modified. Unlike the FragmentHandler version, no alt/ignoreErrors logic applies before the throw; the exception is caught internally only to try the alt URI.","triggerScenarios":"An ESI/SSI include target URL returns 404/500 etc.; render() of the surrogate receives a failed Response for the embedded resource.","commonSituations":"Broken src attribute pointing to a removed route; upstream page erroring; permission changes making an include inaccessible.","solutions":["Fix the src URL of the ESI/SSI tag so it returns 200/304.","Add an alt attribute so the surrogate falls back to an alternate resource on failure.","Add onerror=\"continue\" to the tag to ignore failures for that include."],"exampleFix":"// before\n<esi:include src=\"/_fragment/broken\" />\n// after\n<esi:include src=\"/_fragment/broken\" alt=\"/_fragment/fallback\" onerror=\"continue\" />","handlingStrategy":"fallback","validationCode":"// pre-check upstream URL availability if cheap: HEAD request returning 2xx/304","typeGuard":null,"tryCatchPattern":"try { $content = $surrogate->handle($cache, $uri, $alt, false); } catch (\\RuntimeException $e) { $content = $renderFallback(); }","preventionTips":["Always provide alt attributes on surrogate includes","Use onerror=\"continue\" for non-critical fragments","Monitor upstream fragment endpoint health"],"tags":["php","symfony","http-cache","esi","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"}