Search code examples
phpsymfonysymfony-routing

Symfony throwing ResourceNotFoundException with overridden error templates


I have a small problem. I have already overridden the templates in app/Resources/TwigBundle/views/Exception/ and have error, error404 and error500.html.twig respectively. I have deleted the cache and upon going on a undefined page I get:

Fatal error: Uncaught exception 'Symfony\Component\Routing\Exception\ResourceNotFoundException' in E:\svn\medapp\app\cache\prod\appProdUrlMatcher.php:4044 Stack trace: #0 E:\svn\medapp\app\cache\prod\classes.php(1433): appProdUrlMatcher->match('/asdasd') #1 E:\svn\medapp\app\cache\prod\classes.php(19616): Symfony\Component\Routing\Matcher\UrlMatcher->matchRequest(Object(Symfony\Component\HttpFoundation\Request)) #2 E:\svn\medapp\app\cache\prod\classes.php(2583): JMS\I18nRoutingBundle\Router\I18nRouter->matchRequest(Object(Symfony\Component\HttpFoundation\Request)) #3 [internal function]: Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest(Object(Symfony\Component\HttpKernel\Event\GetResponseEvent), 'kernel.request', Object(Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher)) #4 E:\svn\medapp\app\cache\prod\classes.php(2352): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\GetResponseEvent), 'kernel.request', Object(Symfony\Component\EventDispatcher\ContainerAwareEventDis in E:\svn\medapp\app\cache\prod\classes.php on line 5334 503 Service Unavailable

The prod.log:

[2016-02-26 09:40:49] request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /asdasdas"" at E:\svn\medapp\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\EventListener\RouterListener.php line 176 {"exception":"[object] (Symfony\Component\HttpKernel\Exception\NotFoundHttpException(code: 0): No route found for \"GET /asdasdas\" at E:\svn\medapp\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\EventListener\RouterListener.php:176, Symfony\Component\Routing\Exception\ResourceNotFoundException(code: 0): at E:\svn\medapp\app\cache\prod\appProdUrlMatcher.php:4044)"} [] [2016-02-26 09:40:49] request.CRITICAL: Exception thrown when handling an exception (Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL.") in "MedAppBundle:Default:base.html.twig" at line 95. at E:\svn\medapp\vendor\twig\twig\lib\Twig\Template.php line 182) {"exception":"[object] (Twig_Error_Runtime(code: 0): An exception has been thrown during the rendering of a template (\"The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL.\") in \"MedAppBundle:Default:base.html.twig\" at line 95. at E:\svn\medapp\vendor\twig\twig\lib\Twig\Template.php:182, Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException(code: 0): The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL. at E:\svn\medapp\vendor\symfony\symfony\src\Symfony\Component\Security\Core\Authorization\AuthorizationChecker.php:57)"} [] [2016-02-26 09:40:49] request.CRITICAL: Uncaught PHP Exception Twig_Error_Runtime: "An exception has been thrown during the rendering of a template ("The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL.") in "MedAppBundle:Default:base.html.twig" at line 95." at E:\svn\medapp\vendor\twig\twig\lib\Twig\Template.php line 182 {"exception":"[object] (Twig_Error_Runtime(code: 0): An exception has been thrown during the rendering of a template (\"The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL.\") in \"MedAppBundle:Default:base.html.twig\" at line 95. at E:\svn\medapp\vendor\twig\twig\lib\Twig\Template.php:182, Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException(code: 0): The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL. at E:\svn\medapp\vendor\symfony\symfony\src\Symfony\Component\Security\Core\Authorization\AuthorizationChecker.php:57, Symfony\Component\HttpKernel\Exception\NotFoundHttpException(code: 0): No route found for \"GET /asdasdas\" at E:\svn\medapp\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\EventListener\RouterListener.php:176, Symfony\Component\Routing\Exception\ResourceNotFoundException(code: 0): at E:\svn\medapp\app\cache\prod\appProdUrlMatcher.php:4044)"} [] [2016-02-26 09:40:49] request.CRITICAL: Exception thrown when handling an exception (Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL.") in "MedAppBundle:Default:base.html.twig" at line 95. at E:\svn\medapp\vendor\twig\twig\lib\Twig\Template.php line 182) {"exception":"[object] (Twig_Error_Runtime(code: 0): An exception has been thrown during the rendering of a template (\"The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL.\") in \"MedAppBundle:Default:base.html.twig\" at line 95. at E:\svn\medapp\vendor\twig\twig\lib\Twig\Template.php:182, Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException(code: 0): The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL. at E:\svn\medapp\vendor\symfony\symfony\src\Symfony\Component\Security\Core\Authorization\AuthorizationChecker.php:57)"} []

If I delete or rename the TwigBundle templates and then delete the cache, I get the standard Symfony error page:

Oops! An Error Occurred

The server returned a "404 Not Found".

Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.

What am I missing?


Solution

  • I found the error, sorry for the bother.

    The problem was the error templates were calling parent() for the templates they are extending

    {% extends 'MedAppBundle:Default:base.html.twig' %}
    {% block body %}
        {{ parent() }}
        <div class="container-fluid" >
            <div class="row" >
                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 error-content" >
                    <h1 class="error-title">404</h1>
    
                    <h2 class="error-header2">Resource Not Found
                    </h2>
    
                    <p>The resource requested could not be found on this server!</p>
    
                </div>
            </div>
        </div>
    {% endblock body %}
    

    And in the parent template I was asking for the token storage.

    Something good to learn for the future.