1. Install twig-pack
$ composer require symfony/twig-pack
2. Templates dir
Put this file in your templates dir to catch any error in production
{# templates/bundles/TwigBundle/Exception/error.html.twig #}
{# https://symfony.com/doc/current/controller/error_pages.html#example-404-error-template #}
{% extends 'base.html.twig' %}
{% block body %}
<h1>Error {{exception.statusCode}}</h1>
<h3>Exception</h3>
<pre>
Message: {{ exception.message }}
Code: {{ exception.code }}
Type: {{ exception.class }}
Previous exception: {{ exception.previous }}
</pre>
<h3>File</h3>
<pre>
File: {{ exception.file|split('/')|last }}
Line: {{ exception.line }}
</pre>
<p>
<a href="{{ path('app_home') }}">return to the homepage</a>.
</p>
{% endblock %}
3. Test layout in dev environment
https://localhost/_error/{statusCode}