Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6c95bd0

Browse filesBrowse files
committed
Merge branch '5.3' into 5.4
* 5.3: 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 c576e87 + 3f7748e commit 6c95bd0
Copy full SHA for 6c95bd0

File tree

Expand file treeCollapse file tree

1 file changed

+17
-15
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+17
-15
lines changed

‎http_client.rst

Copy file name to clipboardExpand all lines: http_client.rst
+17-15Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,10 +1020,22 @@ In case the response was canceled using ``$response->cancel()``,
10201020
Handling Exceptions
10211021
~~~~~~~~~~~~~~~~~~~
10221022

1023+
There are three types of exceptions, all of which implement the
1024+
:class:`Symfony\\Contracts\\HttpClient\\Exception\\ExceptionInterface`:
1025+
1026+
* Exceptions implementing the :class:`Symfony\\Contracts\\HttpClient\\Exception\\HttpExceptionInterface`
1027+
are thrown when your code does not handle the status codes in the 300-599 range.
1028+
1029+
* Exceptions implementing the :class:`Symfony\\Contracts\\HttpClient\\Exception\\TransportExceptionInterface`
1030+
are thrown when a lower level issue occurs.
1031+
1032+
* Exceptions implementing the :class:`Symfony\\Contracts\\HttpClient\\Exception\\DecodingExceptionInterface`
1033+
are thrown when a content-type cannot be decoded to the expected representation.
1034+
10231035
When the HTTP status code of the response is in the 300-599 range (i.e. 3xx,
10241036
4xx or 5xx) your code is expected to handle it. If you don't do that, the
1025-
``getHeaders()``, ``getContent()`` and ``toArray()`` methods throw an appropriate exception, all of
1026-
which implement the :class:`Symfony\\Contracts\\HttpClient\\Exception\\HttpExceptionInterface`::
1037+
``getHeaders()``, ``getContent()`` and ``toArray()`` methods throw an appropriate exception, which will
1038+
implement the :class:`Symfony\\Contracts\\HttpClient\\Exception\\HttpExceptionInterface`::
10271039

10281040
// the response of this request will be a 403 HTTP error
10291041
$response = $client->request('GET', 'https://httpbin.org/status/403');
@@ -1061,19 +1073,9 @@ responses in an array::
10611073
This behavior provided at destruction-time is part of the fail-safe design of the
10621074
component. No errors will be unnoticed: if you don't write the code to handle
10631075
errors, exceptions will notify you when needed. On the other hand, if you write
1064-
the error-handling code, you will opt-out from these fallback mechanisms as the
1065-
destructor won't have anything remaining to do.
1066-
1067-
There are three types of exceptions:
1068-
1069-
* Exceptions implementing the :class:`Symfony\\Contracts\\HttpClient\\Exception\\HttpExceptionInterface`
1070-
are thrown when your code does not handle the status codes in the 300-599 range.
1071-
1072-
* Exceptions implementing the :class:`Symfony\\Contracts\\HttpClient\\Exception\\TransportExceptionInterface`
1073-
are thrown when a lower level issue occurs.
1074-
1075-
* Exceptions implementing the :class:`Symfony\\Contracts\\HttpClient\\Exception\\DecodingExceptionInterface`
1076-
are thrown when a content-type cannot be decoded to the expected representation.
1076+
the error-handling code (by calling ``$response->getStatusCode()``), you will
1077+
opt-out from these fallback mechanisms as the destructor won't have anything
1078+
remaining to do.
10771079

10781080
Concurrent Requests
10791081
-------------------

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.