@@ -241,8 +241,8 @@ and set a new ``Exception`` object, or do nothing::
241
241
242
242
.. note ::
243
243
244
- If you want to overwrite the status code (which you should not without a good reason),
245
- set the ``X-Status-Code `` header::
244
+ If you want to overwrite the status code (which you should do not without a good
245
+ reason), set the ``X-Status-Code `` header::
246
246
247
247
$response = new Response(
248
248
'Error',
@@ -252,19 +252,20 @@ and set a new ``Exception`` object, or do nothing::
252
252
)
253
253
);
254
254
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:
255
+ If you do **not ** set the ``X-Status-Code `` header, then Symfony uses the following
256
+ logic to determine the status code:
258
257
259
- :method: `Symfony\\ Component\\ HttpFoundation\\ Response::isClientError `
258
+ * If :method: `Symfony\\ Component\\ HttpFoundation\\ Response::isClientError `,
259
+ :method: `Symfony\\ Component\\ HttpFoundation\\ Response::isServerError ` or
260
+ :method: `Symfony\\ Component\\ HttpFoundation\\ Response::isRedirect ` is true,
261
+ then the status code on your ``Response `` object is used;
260
262
261
- :method: `Symfony\\ Component\\ HttpFoundation\\ Response::isServerError `
263
+ * If the original exception implements
264
+ :class: `Symfony\\ Component\\ HttpKernel\\ Exception\\ HttpExceptionInterface `,
265
+ then ``getStatusCode() `` is called on the exception and used (the headers
266
+ from ``getHeaders() `` are also added);
262
267
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
+ * If both of the above aren't true, then a 500 status code is used.
268
269
269
270
.. seealso ::
270
271
0 commit comments