title: Why HttpClient.GetFromJsonAsync doesn't throw an exception when the response is HTML instead of JSON?
body: <p>I'm learning Blazor.
  I have created a Blazor WASM App with the &quot;ASP.NET Core Hosted&quot; option.
  So I have 3 projects in the solution: Client, Server and Shared.</p>
  <p>The following code is in the Client project and works perfectly when the endpoint is correct (obviously). But at some point I made a mistake and messed up the request URI, and then I noticed that the API returned an HTML page with code 200 OK (as you can see in the Postman screenshot below the code).</p>
  <p>I expected one of my try-catches to get this, but the debugger jumps to the last line (return null) without throwing an exception.</p>
  <p>My first question is why?</p>
  <p>My second question is how can I catch this?</p>
  <p>I know fixing the endpoint fixes everything, but would be nice to have a catch that alerts me when I have mistyped an URI.</p>
  <p>Thanks.</p>
  <pre><code>private readonly HttpClient _httpClient;
  public async Task&lt;List&lt;Collaborator&gt;&gt; GetCollaborators()
  {
      string requestUri = &quot;api/non-existent-endpoint&quot;;
      try
      {
          var response = await _httpClient.GetFromJsonAsync&lt;CollaboratorsResponse&gt;(requestUri);
          if (response == null) 
          {
              // It never enters here. Jumps to the last line of code.
          }
          return response.Collaborators;
      }
      catch (HttpRequestException)
      {
          Console.WriteLine(&quot;An error occurred.&quot;);
      }
      catch (NotSupportedException)
      {
          Console.WriteLine(&quot;The content type is not supported.&quot;);
      }
      catch (JsonException)
      {
          Console.WriteLine(&quot;Invalid JSON.&quot;);
      }
      catch (Exception ex)
      {
          Console.WriteLine(ex.Message);
      }
      return null;
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Qa6gI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Qa6gI.png" alt="Postman Screenshot" /></a></p>