0
votes

I have a symfony application that when running in the production server doesn't handle correctly the 404 errors, this is the error I get in the error log:

    Fatal error:  Uncaught exception 'Symfony\Component\Routing\Exception\ResourceNotFoundException' in /var/www/site/releases/20160119210649/app/cache/prod/appProdUrlMatcher.php:7768
Stack trace:
0 /var/www/site/releases/20160119210649/app/cache/prod/classes.php(1419): appProdUrlMatcher->match('/daf')
1 /var/www/site/releases/20160119210649/app/cache/prod/classes.php(8339): Symfony\Component\Routing\Matcher\UrlMatcher->matchRequest(Object(Symfony\Component\HttpFoundation\Request))
2 /var/www/site/releases/20160119210649/app/cache/prod/classes.php(2483): 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 /var/www/site/releases/20160119210649/app/cache/prod/classes.php(2264): call_user_func(Array, O in /var/www/site/releases/20160119210649/app/cache/prod/classes.php on line 5336

I have my 404 error customized in /app/Resources/TwigBundle/views/Exception/error404.html.twig I've cleared the cached and even restarted php and nginx.

1
@JakubZalas I look into those ones, its not the same case. First case is about a non existent route in the 404 template, not the case. And the second one is about an error extending the template - petekaner
Well, you'll need to give more details... Have you checked the logs? - Jakub Zalas
yes I have, I only see the error I already pasted - petekaner

1 Answers

3
votes

I had the exact same error and found the solution after long research. I have a language switch in my footer and these routes were generated with the current route and the _locale parameter.

{{ path(app.request.get('_route'), app.request.get('_route_params')|merge({'_locale': 'de'})) }}

But on a 404 error there is no route. That ended in this 500 error. Now I wrapped this link into an if statement like this and it works:

<li>
    <a href="{% if app.request.get('_route') != "" and app.request.get('_route_params') is not null %}
            {{ path(app.request.get('_route'), app.request.get('_route_params')|merge({'_locale': 'en'})) }}
        {% else %}
            {{ path("homepage", {'_locale': 'en'}) }}
        {% endif %}">
        English
    </a>
</li>