2

I want to customize the twig template for errors thrown on @Security("has_role('CUSTOM_ADMIN')")

I have already seen a similar issue here but for Symfony 2.

I think that @Security annotation logic bypasses the Twig template overriding because I have followed the directions on the official docs about customizing error pages but those template files are getting ignored and i just get the default Symfony exception page with:

Expression "has_role('CUSTOM_ADMIN')" denied access.

Am I missing something?

Community
  • 1
  • 1
numediaweb
  • 16,362
  • 12
  • 74
  • 110
  • 1
    While you're in the development environment, Symfony shows the big exception page instead of your shiny new customized error page. Are you sure testing it in prod env? http://symfony.com/doc/current/controller/error_pages.html#testing-error-pages-during-development – yceruto May 11 '17 at 13:34
  • 1
    @yceruto This works, please add your comment as an answer so i can make it accepted – numediaweb May 11 '17 at 15:04

1 Answers1

1

While you're in the development environment, Symfony shows the big exception page instead of your shiny new customized error page. So, how can you see what it looks like and debug it?

Fortunately, the default ExceptionController allows you to preview your error pages during development.

To use this feature, you need to have a definition in your routing_dev.yml file like so:

# app/config/routing_dev.yml
_errors:
    resource: "@TwigBundle/Resources/config/routing/errors.xml"
    prefix:   /_error

If you're coming from an older version of Symfony, you might need to add this to your routing_dev.yml file. If you're starting from scratch, the Symfony Standard Edition already contains it for you.

With this route added, you can use URLs like:

http://localhost/app_dev.php/_error/{statusCode}
http://localhost/app_dev.php/_error/{statusCode}.{format}

to preview the error page for a given status code as HTML or for a given status code and format.

Ref: http://symfony.com/doc/current/controller/error_pages.html#testing-error-pages-during-development

yceruto
  • 9,230
  • 5
  • 38
  • 65