Skip to content

Commit 117e239

Browse files
committed
minor #12768 Clarified the two main types of exceptions thrown in HttpClient (Toflar)
This PR was merged into the 4.4 branch. Discussion ---------- Clarified the two main types of exceptions thrown in HttpClient As learned from @nicolas-grekas in symfony/symfony#34837. I guess it's worth clarifying it a little bit :) Commits ------- d815202 Clarified the three main types of exceptions thrown in HttpClient
2 parents ab8e107 + d815202 commit 117e239

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

components/http_client.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,8 @@ Handling Exceptions
436436

437437
When the HTTP status code of the response is in the 300-599 range (i.e. 3xx,
438438
4xx or 5xx) your code is expected to handle it. If you don't do that, the
439-
``getHeaders()`` and ``getContent()`` methods throw an appropriate exception::
439+
``getHeaders()`` and ``getContent()`` methods throw an appropriate exception, all of
440+
which implement the :class:`Symfony\\Contracts\\HttpClient\\Exception\\HttpExceptionInterface`::
440441

441442
// the response of this request will be a 403 HTTP error
442443
$response = $client->request('GET', 'https://httpbin.org/status/403');
@@ -477,6 +478,17 @@ errors, exceptions will notify you when needed. On the other hand, if you write
477478
the error-handling code, you will opt-out from these fallback mechanisms as the
478479
destructor won't have anything remaining to do.
479480

481+
There are three types of exceptions:
482+
483+
* Exceptions implementing the :class:`Symfony\\Contracts\\HttpClient\\Exception\\HttpExceptionInterface` are thrown when
484+
your code does not handle the status codes in the 300-599 range.
485+
486+
* Exceptions implementing the :class:`Symfony\\Contracts\\HttpClient\\Exception\\TransportExceptionInterface` are thrown
487+
when a lower level issue occurs.
488+
489+
* Exceptions implementing the :class:`Symfony\\Contracts\\HttpClient\\Exception\\DecodingExceptionInterface` are thrown
490+
when a content-type cannot be decoded to the expected representation.
491+
480492
Concurrent Requests
481493
-------------------
482494

0 commit comments

Comments
 (0)