From 4db1863cd9b3f6207bb74eda05aa22fa180c5831 Mon Sep 17 00:00:00 2001 From: tabbi89 Date: Sat, 6 Aug 2016 21:47:39 +0200 Subject: [PATCH] Update events.rst --- reference/events.rst | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/reference/events.rst b/reference/events.rst index b415282d8db..a4123bc1537 100644 --- a/reference/events.rst +++ b/reference/events.rst @@ -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', @@ -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 `.