Skip to content

Commit 1e13d5f

Browse files
committed
Clarified the three main types of exceptions thrown in HttpClient
Adjusted docs
1 parent 5b7a873 commit 1e13d5f

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

components/http_client.rst

Lines changed: 25 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');
@@ -476,6 +477,29 @@ component. No errors will be unnoticed: if you don't write the code to handle
476477
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.
480+
=======
481+
482+
Thus, there are two types of exceptions:
483+
484+
* Exceptions implementing the ``HttpExceptionInterface`` are thrown when your code
485+
does not handle the status codes in the 300-599 range.
486+
When streaming responses, these exceptions do not interrupt the stream as you might
487+
still want to read the content of these responses.
488+
That being said, be aware that they are thrown on every single chunk.
489+
490+
* ``TransportExceptionInterface`` exceptions signal a lower level issue.
491+
Thus, when streaming responses, the exception will only be thrown once.
492+
493+
There are three types of exceptions:
494+
495+
* Exceptions implementing the :class:`Symfony\\Contracts\\HttpClient\\Exception\\HttpExceptionInterface` are thrown when
496+
your code does not handle the status codes in the 300-599 range.
497+
498+
* Exceptions implementing the :class:`Symfony\\Contracts\\HttpClient\\Exception\\TransportExceptionInterface` are thrown
499+
when a lower level issue occurs.
500+
501+
* Exceptions implementing the :class:`Symfony\\Contracts\\HttpClient\\Exception\\DecodingExceptionInterface` are thrown
502+
when a content-type cannot be decoded to the expected representation.
479503

480504
Concurrent Requests
481505
-------------------

0 commit comments

Comments
 (0)