@@ -1037,20 +1037,19 @@ There are three types of exceptions, all of which implement the
10371037 are thrown when a content-type cannot be decoded to the expected representation.
10381038
10391039When the HTTP status code of the response is in the 300-599 range (i.e. 3xx,
1040- 4xx or 5xx) your code is expected to handle it. If you don't do that, the
1041- `` getHeaders() ``, `` getContent() `` and `` toArray() `` methods throw an appropriate exception, which will
1042- implement the :class: `Symfony\\ Contracts\\ HttpClient\\ Exception\\ HttpExceptionInterface `::
1040+ 4xx or 5xx), the `` getHeaders() ``, `` getContent() `` and `` toArray() `` methods
1041+ throw an appropriate exception, all of which implement the
1042+ :class: `Symfony\\ Contracts\\ HttpClient\\ Exception\\ HttpExceptionInterface `.
10431043
1044- // the response of this request will be a 403 HTTP error
1045- $response = $client->request('GET', 'https://httpbin.org/status/403');
1044+ To opt-out from this exception and deal with 300-599 status codes on your own,
1045+ pass ``false `` as the optional argument to every call of those methods,
1046+ e.g. ``$response->getHeaders(false); ``.
10461047
1047- // this code results in a Symfony\Component\HttpClient\Exception\ClientException
1048- // because it doesn't check the status code of the response
1049- $content = $response->getContent();
1048+ If you do not call any of these 3 methods at all, the exception will still be thrown
1049+ when the ``$response `` object is destructed.
10501050
1051- // pass FALSE as the optional argument to not throw an exception and return
1052- // instead the original response content (even if it's an error message)
1053- $content = $response->getContent(false);
1051+ Calling ``$response->getStatusCode() `` is enough to disable this behavior
1052+ (but then don't miss checking the status code yourself).
10541053
10551054While responses are lazy, their destructor will always wait for headers to come
10561055back. This means that the following request *will * complete; and if e.g. a 404
0 commit comments