0

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.

petekaner
  • 8,071
  • 5
  • 29
  • 52
  • 1
    Possible duplicate of [Symfony2 error 500 instead of 404 at production](http://stackoverflow.com/questions/10426899/symfony2-error-500-instead-of-404-at-production) – Jakub Zalas Jan 19 '16 at 21:53
  • Another one: http://stackoverflow.com/questions/17510216/symfony2-resourcenotfoundexception-when-using-extends-in-a-twig-template – Jakub Zalas Jan 19 '16 at 21:54
  • @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 Jan 19 '16 at 21:56
  • Well, you'll need to give more details... Have you checked the logs? – Jakub Zalas Jan 19 '16 at 21:58
  • yes I have, I only see the error I already pasted – petekaner Jan 19 '16 at 22:05
  • As I said with no additional information there's not much we can do. You could at least paste the customised 404 template, or routing configuration. I see you use JMSI18nRoutingBundle - perhaps disabling it would shed more light. Try to reproduce the problem on a fresh Symfony installation. – Jakub Zalas Jan 19 '16 at 22:08
  • Are you sure you are not trying to include a non existent template ? Check out your twig `include` and the path of the templates your are trying to access. – COil Jan 20 '16 at 10:34
  • But if twig couldn't include a template then the error wouldn't be different? – petekaner Jan 20 '16 at 10:47

1 Answers1

3

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>
Niklas
  • 31
  • 6