Skip to content

Commit 793659c

Browse files
committed
don't break TwigBundle error page preview. should fix #958
1 parent 6e5789a commit 793659c

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Controller/ExceptionController.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public function showAction(Request $request, $exception, DebugLoggerInterface $l
8787
$code = $this->getStatusCode($exception);
8888
$viewHandler = $this->container->get('fos_rest.view_handler');
8989
$parameters = $this->getParameters($viewHandler, $currentContent, $code, $exception, $logger, $format);
90+
$showException = $request->attributes->get('showException', $this->container->get('kernel')->isDebug());
9091

9192
try {
9293
if (!$viewHandler->isFormatTemplating($format)) {
@@ -97,7 +98,7 @@ public function showAction(Request $request, $exception, DebugLoggerInterface $l
9798
$view->setFormat($format);
9899

99100
if ($viewHandler->isFormatTemplating($format)) {
100-
$view->setTemplate($this->findTemplate($request, $format, $code, $this->container->get('kernel')->isDebug()));
101+
$view->setTemplate($this->findTemplate($request, $format, $code, $showException));
101102
}
102103

103104
$response = $viewHandler->handle($view);
@@ -265,19 +266,19 @@ protected function getParameters(ViewHandler $viewHandler, $currentContent, $cod
265266
* @param Request $request
266267
* @param string $format
267268
* @param int $statusCode
268-
* @param bool $debug
269+
* @param bool $showException
269270
*
270271
* @return TemplateReference
271272
*/
272-
protected function findTemplate(Request $request, $format, $statusCode, $debug)
273+
protected function findTemplate(Request $request, $format, $statusCode, $showException)
273274
{
274-
$name = $debug ? 'exception' : 'error';
275-
if ($debug && 'html' == $format) {
275+
$name = $showException ? 'exception' : 'error';
276+
if ($showException && 'html' == $format) {
276277
$name = 'exception_full';
277278
}
278279

279280
// when not in debug, try to find a template for the specific HTTP status code and format
280-
if (!$debug) {
281+
if (!$showException) {
281282
$template = new TemplateReference('TwigBundle', 'Exception', $name.$statusCode, $format, 'twig');
282283
if ($this->container->get('templating')->exists($template)) {
283284
return $template;
@@ -293,6 +294,6 @@ protected function findTemplate(Request $request, $format, $statusCode, $debug)
293294
// default to a generic HTML exception
294295
$request->setRequestFormat('html');
295296

296-
return new TemplateReference('TwigBundle', 'Exception', $name, 'html', 'twig');
297+
return new TemplateReference('TwigBundle', 'Exception', $showException ? 'exception_full' : $name, 'html', 'twig');
297298
}
298299
}

0 commit comments

Comments
 (0)