1
votes

So far, my "TwigBundle" custom error404.html.twig page displays correctly on production mode when I throw:

$this->createNotFoundException('whatevs');

However, when a "NotFoundHttpException" is thrown by Symfony (such as whenever a route is not found), the "no route found" page displays indeed on app_dev, mentioning "404 Not Found", but on production mode it just displays a blank page...

Which does not seem normal since, according to the Symfony documentation: "The createNotFoundException() method creates a special NotFoundHttpException object, which ultimately triggers a 404 HTTP response inside Symfony."

Then why don't I get the same behavior? Is there something I am missing?

I am using the master branch.

EDIT: Here is my security.yml file, I am using FOSUserBundle and FOSFacebookBundle:

security:
providers:
    chain_provider:
        chain:
            providers: [fos_userbundle, my_fos_facebook_provider]
    fos_userbundle:
        id: fos_user.user_manager
    my_fos_facebook_provider:
        id: my.facebook.user

encoders:
    "FOS\UserBundle\Model\UserInterface": sha512

firewalls:
    public:
        pattern:   ^/
        fos_facebook:
            app_url: "http://apps.facebook.com/***/"
            server_url: "http://localhost/facebookApp/"
            login_path: /login
            check_path: /checkFb
            default_target_path: /
            provider: chain_provider
        form_login:
            login_path: /login
            check_path: /login_check
            provider: chain_provider
            remember_me:   true
            csrf_provider: form.csrf_provider
        remember_me:
            key:           %secret%
        anonymous: true
        logout: true
    login:                                           
        pattern:   ^/(login$|register|resetting)  
        anonymous: true

role_hierarchy:
    ROLE_ADMIN:       ROLE_ADMIN
    ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALOOW_TO_SWITCH]
    ROLE_USER:        ROLE_USER

access_control:
    - { path: ^/, role: [IS_AUTHENTICATED_ANONYMOUSLY] }
    - { path: ^/secured/, role: [IS_AUTHENTICATED_FULLY] } # This is the route secured with fos_facebook
    - { path: ^/facebook/,           role: [ROLE_FACEBOOK] }
2

2 Answers

0
votes

Had the same problem. See https://github.com/symfony/symfony/issues/5320 You're probably calling is_granted on the errorpage or layout.html.twig. Read the answer of Stof how to solve this.

0
votes

Per Stof in https://github.com/symfony/symfony/issues/5320:

"You avoid calling is_granted in the error page (or you do it only when app.user is not null, which would occur when there is no token or when the token is anonymous). ... The issue is that the router runs before the firewall. So if the router throws an exception because it does not match a route, your error page is not behind a firewall (as it was not called)."