title: Why can't I access the response content when the Symfony HTTP Client encounters an error, and an exception is thrown instead?
body: <p>I want to make a request to retrieve user info from OAUTH server with Symfony HttpClient but I can't fetch fetch the response directly when encountering an error response, because the client throws an exception.</p>
  <p><strong>My UserProvider:</strong></p>
  <pre><code>    public function loadUserByUsername($username)
      {
          try {
              $response = $this-&gt;httpClient-&gt;request(
                  'GET',
                  $this-&gt;baseUrl . '/userinfo',
                  [
                      'headers' =&gt; [
                          'Accept' =&gt; 'application/json',
                          'Content-Type' =&gt; 'application/json'
                      ],
                      'auth_bearer' =&gt; $username
                  ]
              );
  
              var_dump($response-&gt;toArray());die;
  
          } catch (\Exception $e) {
              var_dump($e-&gt;getMessage());die;
              throw new UsernameNotFoundException($e-&gt;getMessage());
          }
      }
  </code></pre>
  <p>When I call <code>$response-&gt;toArray()</code> or <code>$response-&gt;getContent()</code>, an exception is thrown and I get the following error message on Postman</p>
  <pre><code>&lt;pre class='xdebug-var-dump' dir='ltr'&gt;
  &lt;small&gt;/var/www/html/backend/src/Security/Provider/KeycloakUserProvider.php:50:&lt;/small&gt;&lt;small&gt;string&lt;/small&gt; &lt;font color='#cc0000'&gt;'HTTP/2 401  returned for &amp;quot;https://oauth_server/userinfo&amp;quot;.'&lt;/font&gt; &lt;i&gt;(length=127)&lt;/i&gt;
  &lt;/pre&gt;
  </code></pre>
  <p>An example of the response received on the browser:</p>
  <pre><code>{&quot;error&quot;:&quot;invalid_request&quot;,&quot;error_description&quot;:&quot;Token not provided&quot;}
  </code></pre>
  <p>Why can't I access the response directly by calling <code>$response-&gt;toArray()</code>?</p>