Skip to content

Commit e25e3a9

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: Clarify which is the top level exception for http client if you want to catch everything Clarify what error handling is for http-client
2 parents b819b4c + 6c95bd0 commit e25e3a9

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

http_client.rst

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -998,10 +998,22 @@ In case the response was canceled using ``$response->cancel()``,
998998
Handling Exceptions
999999
~~~~~~~~~~~~~~~~~~~
10001000

1001+
There are three types of exceptions, all of which implement the
1002+
:class:`Symfony\\Contracts\\HttpClient\\Exception\\ExceptionInterface`:
1003+
1004+
* Exceptions implementing the :class:`Symfony\\Contracts\\HttpClient\\Exception\\HttpExceptionInterface`
1005+
are thrown when your code does not handle the status codes in the 300-599 range.
1006+
1007+
* Exceptions implementing the :class:`Symfony\\Contracts\\HttpClient\\Exception\\TransportExceptionInterface`
1008+
are thrown when a lower level issue occurs.
1009+
1010+
* Exceptions implementing the :class:`Symfony\\Contracts\\HttpClient\\Exception\\DecodingExceptionInterface`
1011+
are thrown when a content-type cannot be decoded to the expected representation.
1012+
10011013
When the HTTP status code of the response is in the 300-599 range (i.e. 3xx,
10021014
4xx or 5xx) your code is expected to handle it. If you don't do that, the
1003-
``getHeaders()``, ``getContent()`` and ``toArray()`` methods throw an appropriate exception, all of
1004-
which implement the :class:`Symfony\\Contracts\\HttpClient\\Exception\\HttpExceptionInterface`::
1015+
``getHeaders()``, ``getContent()`` and ``toArray()`` methods throw an appropriate exception, which will
1016+
implement the :class:`Symfony\\Contracts\\HttpClient\\Exception\\HttpExceptionInterface`::
10051017

10061018
// the response of this request will be a 403 HTTP error
10071019
$response = $client->request('GET', 'https://httpbin.org/status/403');
@@ -1039,19 +1051,9 @@ responses in an array::
10391051
This behavior provided at destruction-time is part of the fail-safe design of the
10401052
component. No errors will be unnoticed: if you don't write the code to handle
10411053
errors, exceptions will notify you when needed. On the other hand, if you write
1042-
the error-handling code, you will opt-out from these fallback mechanisms as the
1043-
destructor won't have anything remaining to do.
1044-
1045-
There are three types of exceptions:
1046-
1047-
* Exceptions implementing the :class:`Symfony\\Contracts\\HttpClient\\Exception\\HttpExceptionInterface`
1048-
are thrown when your code does not handle the status codes in the 300-599 range.
1049-
1050-
* Exceptions implementing the :class:`Symfony\\Contracts\\HttpClient\\Exception\\TransportExceptionInterface`
1051-
are thrown when a lower level issue occurs.
1052-
1053-
* Exceptions implementing the :class:`Symfony\\Contracts\\HttpClient\\Exception\\DecodingExceptionInterface`
1054-
are thrown when a content-type cannot be decoded to the expected representation.
1054+
the error-handling code (by calling ``$response->getStatusCode()``), you will
1055+
opt-out from these fallback mechanisms as the destructor won't have anything
1056+
remaining to do.
10551057

10561058
Concurrent Requests
10571059
-------------------

0 commit comments

Comments
 (0)