Skip to content

Commit

Permalink
bug #23283 [TwigBundle] add back exception check (xabbuh)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.7 branch.

Discussion
----------

[TwigBundle] add back exception check

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23268
| License       | MIT
| Doc PR        |

#23268 introduced a regression in that the full exception page was not shown anymore in case a template for the given format (if not `html`) could not be found.

Commits
-------

46c38df [TwigBundle] add back exception check
  • Loading branch information
fabpot committed Jun 24, 2017
2 parents 9fc9cc4 + 46c38df commit 73e9348
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Expand Up @@ -125,7 +125,7 @@ protected function findTemplate(Request $request, $format, $code, $showException
// default to a generic HTML exception
$request->setRequestFormat('html');

return new TemplateReference('TwigBundle', 'Exception', $name, 'html', 'twig');
return new TemplateReference('TwigBundle', 'Exception', $showException ? 'exception_full' : $name, 'html', 'twig');
}

// to be removed when the minimum required version of Twig is >= 3.0
Expand Down
Expand Up @@ -48,6 +48,20 @@ public function testFallbackToHtmlIfNoTemplateForRequestedFormat()
$this->assertEquals('html', $request->getRequestFormat());
}

public function testFallbackToHtmlWithFullExceptionIfNoTemplateForRequestedFormatAndExceptionsShouldBeShown()
{
$twig = $this->createTwigEnv(array('TwigBundle:Exception:exception_full.html.twig' => '<html></html>'));

$request = $this->createRequest('txt');
$request->attributes->set('showException', true);
$exception = FlattenException::create(new \Exception());
$controller = new ExceptionController($twig, false);

$controller->showAction($request, $exception);

$this->assertEquals('html', $request->getRequestFormat());
}

public function testResponseHasRequestedMimeType()
{
$twig = $this->createTwigEnv(array('TwigBundle:Exception:error.json.twig' => '{}'));
Expand Down

0 comments on commit 73e9348

Please sign in to comment.