8000 minor #47733 [TwigBridge] Avoid double render when an exception is th… · symfony/symfony@c2af1fd · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit c2af1fd

Browse files
committed
minor #47733 [TwigBridge] Avoid double render when an exception is thrown in !debug (lyrixx)
This PR was merged into the 6.2 branch. Discussion ---------- [TwigBridge] Avoid double render when an exception is thrown in !debug | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | In !debug, the error is rendered a first time in `TwigErrorRenderer::render()` via `$exception = $this->fallbackErrorRenderer->render($exception);` But in !debug, the error is rendered another time with twig. Commits ------- 301c53b [TwigBridge] Avoid double render when an exception is thrown in !debug
2 parents 036de42 + 301c53b commit c2af1fd

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/Symfony/Bridge/Twig/ErrorRenderer/TwigErrorRenderer.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ public function __construct(Environment $twig, HtmlErrorRenderer $fallbackErrorR
4141

4242
public function render(\Throwable $exception): FlattenException
4343
{
44-
$exception = $this->fallbackErrorRenderer->render($exception);
45-
$debug = \is_bool($this->debug) ? $this->debug : ($this->debug)($exception);
44+
$flattenException = FlattenException::createFromThrowable($exception);
45+
$debug = \is_bool($this->debug) ? $this->debug : ($this->debug)($flattenException);
4646

47-
if ($debug || !$template = $this->findTemplate($exception->getStatusCode())) {
48-
return $exception;
47+
if ($debug || !$template = $this->findTemplate($flattenException->getStatusCode())) {
48+
return $this->fallbackErrorRenderer->render($exception);
4949
}
5050

51-
return $exception->setAsString($this->twig->render($template, [
52-
'exception' => $exception,
53-
'status_code' => $exception->getStatusCode(),
54-
'status_text' => $exception->getStatusText(),
51+
return $flattenException->setAsString($this->twig->render($template, [
52+
'exception' => $flattenException,
53+
'status_code' => $flattenException->getStatusCode(),
54+
'status_text' => $flattenException->getStatusText(),
5555
]));
5656
}
5757

0 commit comments

Comments
 (0)
0