Skip to content

Commit 4db1863

Browse files
committed
Update events.rst
1 parent b265132 commit 4db1863

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

reference/events.rst

+16-4
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,8 @@ and set a new ``Exception`` object, or do nothing::
241241

242242
.. note::
243243

244-
As Symfony ensures that the Response status code is set to the most
245-
appropriate one depending on the exception, setting the status on the
246-
response won't work. If you want to overwrite the status code (which you
247-
should not without a good reason), set the ``X-Status-Code`` header::
244+
If you want to overwrite the status code (which you should not without a good reason),
245+
set the ``X-Status-Code`` header::
248246

249247
$response = new Response(
250248
'Error',
@@ -254,6 +252,20 @@ and set a new ``Exception`` object, or do nothing::
254252
)
255253
);
256254

255+
This indeed will skip all checks that Symfony processes on setting response status code.
256+
First check that Symfony does is fitting response status code.
257+
Symfony leaves set status code as it is if it belongs to one of group:
258+
259+
:method:`Symfony\\Component\\HttpFoundation\\Response::isClientError`
260+
261+
:method:`Symfony\\Component\\HttpFoundation\\Response::isServerError`
262+
263+
:method:`Symfony\\Component\\HttpFoundation\\Response::isRedirect`
264+
265+
If status code is different then Symfony checks instance of raised Exception if it is
266+
:class:`Symfony\\Component\\HttpKernel\\Exception\\HttpExceptionInterface` then its headers including status code are passed to response.
267+
Otherwise status code 500 is set to response.
268+
257269
.. seealso::
258270

259271
Read more on the :ref:`kernel.exception event <component-http-kernel-kernel-exception>`.

0 commit comments

Comments
 (0)