Skip to content

Commit c6805ff

Browse files
committed
minor #15905 [HttpClient] Clarify which is the top level exception for http client if you want to catch everything (Seldaek)
This PR was merged into the 4.4 branch. Discussion ---------- [HttpClient] Clarify which is the top level exception for http client if you want to catch everything The fact that right now https://symfony.com/doc/current/http_client.html#handling-exceptions starts by mentioning ` an appropriate exception, all of which implement the [...]HttpExceptionInterface` is kinda misleading as that is only the interface for http-status-codes exceptions, not for all http client exceptions. Commits ------- 9f7631b Clarify which is the top level exception for http client if you want to catch everything
2 parents 817009c + 9f7631b commit c6805ff

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

http_client.rst

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -924,10 +924,22 @@ In case the response was canceled using ``$response->cancel()``,
924924
Handling Exceptions
925925
~~~~~~~~~~~~~~~~~~~
926926

927+
There are three types of exceptions, all of which implement the
928+
:class:`Symfony\\Contracts\\HttpClient\\Exception\\ExceptionInterface`:
929+
930+
* Exceptions implementing the :class:`Symfony\\Contracts\\HttpClient\\Exception\\HttpExceptionInterface`
931+
are thrown when your code does not handle the status codes in the 300-599 range.
932+
933+
* Exceptions implementing the :class:`Symfony\\Contracts\\HttpClient\\Exception\\TransportExceptionInterface`
934+
are thrown when a lower level issue occurs.
935+
936+
* Exceptions implementing the :class:`Symfony\\Contracts\\HttpClient\\Exception\\DecodingExceptionInterface`
937+
are thrown when a content-type cannot be decoded to the expected representation.
938+
927939
When the HTTP status code of the response is in the 300-599 range (i.e. 3xx,
928940
4xx or 5xx) your code is expected to handle it. If you don't do that, the
929-
``getHeaders()``, ``getContent()`` and ``toArray()`` methods throw an appropriate exception, all of
930-
which implement the :class:`Symfony\\Contracts\\HttpClient\\Exception\\HttpExceptionInterface`::
941+
``getHeaders()``, ``getContent()`` and ``toArray()`` methods throw an appropriate exception, which will
942+
implement the :class:`Symfony\\Contracts\\HttpClient\\Exception\\HttpExceptionInterface`::
931943

932944
// the response of this request will be a 403 HTTP error
933945
$response = $client->request('GET', 'https://httpbin.org/status/403');
@@ -969,17 +981,6 @@ the error-handling code (by calling ``$response->getStatusCode()``), you will
969981
opt-out from these fallback mechanisms as the destructor won't have anything
970982
remaining to do.
971983

972-
There are three types of exceptions:
973-
974-
* Exceptions implementing the :class:`Symfony\\Contracts\\HttpClient\\Exception\\HttpExceptionInterface`
975-
are thrown when your code does not handle the status codes in the 300-599 range.
976-
977-
* Exceptions implementing the :class:`Symfony\\Contracts\\HttpClient\\Exception\\TransportExceptionInterface`
978-
are thrown when a lower level issue occurs.
979-
980-
* Exceptions implementing the :class:`Symfony\\Contracts\\HttpClient\\Exception\\DecodingExceptionInterface`
981-
are thrown when a content-type cannot be decoded to the expected representation.
982-
983984
Concurrent Requests
984985
-------------------
985986

0 commit comments

Comments
 (0)