@@ -14,16 +14,16 @@ a special **exception page** with lots of debug information to help you quickly
14
14
discover the root problem:
15
15
16
16
.. image :: /images/cookbook/controller/error_pages/exceptions-in-dev-environment.png
17
- :alt: A typical exception page in development environment
17
+ :alt: A typical exception page in the development environment
18
18
19
19
Since these pages contain a lot of sensitive internal information, Symfony won't
20
20
display them in the production environment. Instead, it'll show a simple and
21
21
generic **error page **:
22
22
23
23
.. image :: /images/cookbook/controller/error_pages/errors-in-prod-environment.png
24
- :alt: A typical error page in production environment
24
+ :alt: A typical error page in the production environment
25
25
26
- Error pages for production environment can be customized in different ways,
26
+ Error pages for the production environment can be customized in different ways
27
27
depending on your needs:
28
28
29
29
#. If you just want to change the contents and styles of the error pages to match
@@ -53,7 +53,7 @@ templates defined for different types of errors and content formats.
53
53
.. _cookbook-error-pages-by-status-code :
54
54
55
55
The logic followed by the ``ExceptionController `` to pick one of the available
56
- templates is based on the HTTP status code and request format:
56
+ templates is based on the HTTP status code and the request format:
57
57
58
58
#. Look for a template for the given format and status code (like ``error404.json.twig ``
59
59
or ``error500.xml.twig ``);
@@ -65,6 +65,8 @@ templates is based on the HTTP status code and request format:
65
65
#. If none of the previous template exist, fall back to the generic HTML template
66
66
(``error.html.twig ``).
67
67
68
+ .. _overriding-or-adding-templates :
69
+
68
70
To override these templates, simply rely on the standard Symfony method for
69
71
:ref: `overriding templates that live inside a bundle <overriding-bundle-templates >`.
70
72
For example, to override the 404 error template for HTML pages, create a new
@@ -129,7 +131,7 @@ Testing Error Pages during Development
129
131
130
132
One of the biggest hurdles of testing how do custom error pages look in your
131
133
application is the fact that Symfony ignores them in the development environment
132
- and displays instead the default exception pages.
134
+ and displays the default exception pages instead .
133
135
134
136
You may be tempted to set the ``kernel.debug `` parameter to ``false `` to disable
135
137
the debug mode in the development environment. However, this practice is not
@@ -142,6 +144,7 @@ custom error pages for arbitrary HTTP status codes even when ``kernel.debug`` is
142
144
set to ``true ``.
143
145
144
146
.. _custom-exception-controller :
147
+ .. _replacing-the-default-exceptioncontroller :
145
148
146
149
Overriding the Default ExceptionController
147
150
------------------------------------------
@@ -188,8 +191,8 @@ configuration option to point to it:
188
191
));
189
192
190
193
The :class: `Symfony\\ Component\\ HttpKernel\\ EventListener\\ ExceptionListener `
191
- class used by TwigBundle as a listener of the ``kernel.exception `` event creates
192
- the Request that will be dispatched to your controller. In addition, your controller
194
+ class used by the TwigBundle as a listener of the ``kernel.exception `` event creates
195
+ the request that will be dispatched to your controller. In addition, your controller
193
196
will be passed two parameters:
194
197
195
198
``exception ``
@@ -215,13 +218,11 @@ class catches it and dispatches a ``kernel.exception`` event. This gives you the
215
218
power to convert the exception into a ``Response `` in a few different ways.
216
219
217
220
Working with this event is actually much more powerful than what has been explained
218
- before but also requires a thorough understanding of Symfony internals. Suppose
221
+ before, but also requires a thorough understanding of Symfony internals. Suppose
219
222
that your code throws specialized exceptions with a particular meaning to your
220
223
application domain.
221
224
222
- If you extend the default ``ExceptionListener ``, all you can get is the HTTP
223
- status code and message and display a nice-looking error page. However,
224
- :doc: `writing your own event listener </cookbook/service_container/event_listener >`
225
+ :doc: `Writing your own event listener </cookbook/service_container/event_listener >`
225
226
for the ``kernel.exception `` event allows you to have a closer look at the exception
226
227
and take different actions depending on it. Those actions might include logging
227
228
the exception, redirecting the user to another page or rendering specialized
0 commit comments