0
votes

I am building an app using Symfony 4.4. I am trying to render custom 404 error page. I followed the documentation and created error.html.twig and error404.html.twig files in templates/bundles/TwigBundle/Exception. However I still get the 'Oops! An Error Occurred' with code 500 page that is by default from symfony. Can someone point what can have I done wrong? In dev mode I see that the app throws NotFoundHttpException but in prod mode I always get the page with code 500 even if I visit an undefined route. This is what I get when I visit an undefiend route: 500 error

1

1 Answers

0
votes

You can use the built-in Twig error renderer to override the default error templates. Both the TwigBundle and TwigBridge need to be installed for this When the error page loads, Symfony\Bridge\Twig\ErrorRenderer\TwigErrorRenderer is used to render a Twig template to show the user.

This renderer uses the HTTP status code and the following logic to determine the template filename:

Look for a template for the given status code (like error500.html.twig); If the previous template doesn’t exist, discard the status code and look for a generic error template (error.html.twig). To override these templates, rely on the standard Symfony method for overriding templates that live inside a bundle and put them in the templates/bundles/TwigBundle/Exception/ directory.