0
votes

I've got an issue when it comes to using Custom Error Templates in Symfony 4.4 Flex. Everything has been set properly according to the guide from https://symfony.com/doc/4.4/controller/error_pages.html

I can access the Custom Error Templates via /_error/{errorCode} when I run the application with APP_ENV=dev - but if I change APP_ENV to prod (with APP_DEBUG set to false/0 of course), I get the default Symfony "500 Internal Server Error" page. I even tested it after deploying the application on the remote host, and it's the same issue when I try to access /random-unexisting-page (already got the error404.html.twig template set and it works on 'dev' via /_error/404).

I want to know, does it have anything to do with other configuration within /config/ ? Have you got any idea what the issue could be ?

1
I suggest you create a small reproducer app and report it to the Symfony repo. It's hard to know what is missing on your side without more information.yceruto

1 Answers

0
votes

I made a few tries and I think I've understood your problem.

So when you want to create a personalized error page, first you need to add, under the template directory, the following path, same as your link said

templates/
└─ bundles/
   └─ TwigBundle/
      └─ Exception/
         ├─ error404.html.twig
         ├─ error403.html.twig
         └─ error.html.twig      # All other HTML errors (including 500)

The most common error is the 500 so you can add this: error500.html.twig or just leave the generic one, it's up to you.

The importamt thing is that whenever you add a file error in the directory or you simply make a change in an existing file: you MUST launch the command to clear the cache (you can only launch this command when the project has no errors). If you don’t do this the changes wont be visualized.

STEPS:

  • fix the error or start from a previous working build
  • launch the clear command: php bin\console cache:clear, you'll get something like that result_of_clear_cache
  • refresh the page and you should see the new page

PS. if you need some visual references:

path

error_file

result_on_browser