Skip to content

Update events.rst #6857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 15, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions reference/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,8 @@ and set a new ``Exception`` object, or do nothing::

.. note::

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

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

This indeed will skip all checks that Symfony processes on setting response status code.
First check that Symfony does is fitting response status code.
Symfony leaves set status code as it is if it belongs to one of group:

:method:`Symfony\\Component\\HttpFoundation\\Response::isClientError`

:method:`Symfony\\Component\\HttpFoundation\\Response::isServerError`

:method:`Symfony\\Component\\HttpFoundation\\Response::isRedirect`

If status code is different then Symfony checks instance of raised Exception if it is
:class:`Symfony\\Component\\HttpKernel\\Exception\\HttpExceptionInterface` then its headers including status code are passed to response.
Otherwise status code 500 is set to response.

.. seealso::

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