2

I've followed the Symfony2.2 documentation on customising error templates and overridden the default error template at app/Resources/TwigBundle/views/Exception/error.html.twig as described for Twig.

In some controllers I am throwing a custom 404 when a DB entity doesn't exist for example. I'm doing that with:

throw $this->createNotFoundException('Thing not found');

When my custom template exists this exception is not being caught, so my error page is never rendered and I get a fatal error. I've not changed anything to do with exception handlers, so I don't understand why overriding the template breaks Symfony error rendering functionality.

It looks like the Twig exception controller's showAction is being executed, but the exception still gets thrown out of the stack.

What needs to be done to ensure the exception is caught and rendered?

Additional info:

The following is logged. (changed name of client only)

[2013-05-22 16:26:22] request.INFO: Matched route "show_thing" (parameters: "_controller": "Client\SiteBundle\Controller\ThingController::indexAction", "id": "thing", "_route": "show_thing") [] []
[2013-05-22 16:26:22] security.INFO: No expression found; abstaining from voting. [] []
[2013-05-22 16:26:22] request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "thing not found" at /home/vhosts/client/symfony/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php line 149 [] []
4

2 回答 2

3

我解决了。

我的模板有一个未在布局中定义的块。

此错误未记录,但足以破坏渲染,

感谢@nifr 的所有帮助。

于 2013-05-22T15:47:38.417 回答
0

您的问题是指 symfony 控制器中的createNotFoundException方法。

Symfony API - Symfony/Bundle/FrameworkBundle/Controller/Controller

GitHub 上的代码

要真正显示自定义错误模板,您必须在prod环境中使用 Symfony,因为异常仅在此处捕获。

在开发环境中,symfony 使用自己修改过的 php 错误处理程序来显示堆栈跟踪。这些异常并没有被错误处理程序捕获。

您是否检查过内核异常侦听器是否已在服务容器中正确注册?

app/console container:debug --show-private
于 2013-05-22T15:15:11.010 回答