In my Symfony2 project I\'m getting at development mode correct 404 Exception screen. But I\'m getting blank screen with HTTP status code 500 instead of 404 at production mo
In my case (symfony 2.3) I was getting a 200 status code, so the error pages didn't load. That's how I solved it:
https://groups.google.com/d/msg/Symfony2/zNWNmQIq3nk/lVs4uC7QMIcJ
I had the same issue,
But my isGranted
was in the php side. So I added a token check :
Before :
if ($this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')
After :
if ($this->get('security.token_storage')->getToken() && $this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')
maybe app/Resources/TwigBundle/views/Exception/error.html.twig references another base-layout-template which does not exists - this was the problem in my case
Just an complementary note to the given answers: The ResourceNotFoundException
can also be thrown if you are trying to include a non existent template. A typical case, is that you refactored your application code but you forgot to update your error pages as they are located in app/Resources
and not in your src/
folder or including a given template that use a variable or service that is not defined in the "error" context.
The most likely reason you're getting a 500 error / blank page on production (app.php), even when you've defined a custom error page ( e.g. app/Resources/TwigBundle/views/Exception/error404.html.twig ) is that your error template is calling the is_granted twig function, without checking if the user is logged in.
Steps to debug:
1)Check app/logs/prod.log. Do you see an error like this?
request.ERROR: Exception thrown when handling an exception (Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("The security context contains no authentication token. One possible reason may be that there is no firewall configured for this URL.")
2)If you see the error mentioned above, see if you can find a reference to is_granted in your error template. Check that the user is logged in before calling is_granted. E.g.:
{% if app.user is not null and is_granted('ROLE_ADMIN') %}
<p>Text goes here</p>
{% else %}
3)If you can't find a reference to is_granted in your template, see if there's a call to knp_menu_render(), which is used by the KNP menu bundle. Check in any extended template as well. Wrap the call to knp_menu_render in a check to verify that the user is logged in:
{% if app.user %}
{{ knp_menu_render() }}
{% endif %}
For more information, check the comment by stof at the end of this page: https://github.com/symfony/symfony/issues/5320