@@ -1063,20 +1063,19 @@ There are three types of exceptions, all of which implement the
1063
1063
are thrown when a content-type cannot be decoded to the expected representation.
1064
1064
1065
1065
When the HTTP status code of the response is in the 300-599 range (i.e. 3xx,
1066
- 4xx or 5xx) your code is expected to handle it. If you don't do that, the
1067
- `` getHeaders() ``, `` getContent() `` and `` toArray() `` methods throw an appropriate exception, which will
1068
- implement the :class: `Symfony\\ Contracts\\ HttpClient\\ Exception\\ HttpExceptionInterface `::
1066
+ 4xx or 5xx), the `` getHeaders() ``, `` getContent() `` and `` toArray() `` methods
1067
+ throw an appropriate exception, all of which implement the
1068
+ :class: `Symfony\\ Contracts\\ HttpClient\\ Exception\\ HttpExceptionInterface `.
1069
1069
1070
- // the response of this request will be a 403 HTTP error
1071
- $response = $client->request('GET', 'https://httpbin.org/status/403');
1070
+ To opt-out from this exception and deal with 300-599 status codes on your own,
1071
+ pass ``false `` as the optional argument to every call of those methods,
1072
+ e.g. ``$response->getHeaders(false); ``.
1072
1073
1073
- // this code results in a Symfony\Component\HttpClient\Exception\ClientException
1074
- // because it doesn't check the status code of the response
1075
- $content = $response->getContent();
1074
+ If you do not call any of these 3 methods at all, the exception will still be thrown
1075
+ when the ``$response `` object is destructed.
1076
1076
1077
- // pass FALSE as the optional argument to not throw an exception and return
1078
- // instead the original response content (even if it's an error message)
1079
- $content = $response->getContent(false);
1077
+ Calling ``$response->getStatusCode() `` is enough to disable this behavior
1078
+ (but then don't miss checking the status code yourself).
1080
1079
1081
1080
While responses are lazy, their destructor will always wait for headers to come
1082
1081
back. This means that the following request *will * complete; and if e.g. a 404
0 commit comments