title: Using HttpResponseMessage to view errors
body: <p>I can use the following code which works fine to log in using my Web API.  However, whensomething goes wrong and an error is returned, I don't know how to get at the contect of the HttpResponseMessage.  If I just use the ReadAsStringAsync() method, I get the error in the string, but what type is it?  If I know the type I can get the object.</p>
  
  <pre><code>HttpResponseMessage response = await client.PostAsJsonAsync("api/Login", loginObject);
  if (response.IsSuccessStatusCode)
  {
      var _logonResponse = await response.Content.ReadAsAsync&lt;TokenResponseModel&gt;();
  }
  else
  {
      // an error has occured, but what is the type to read?
      var test = await response.Content.ReadAsStringAsync();
  }
  </code></pre>
  
  <p>On the server it is returning;</p>
  
  <pre><code>BadRequest(ModelState).
  </code></pre>
  
  <p>Thanks for any help.</p>
  
  <p>EDIT:  I have since resolved the issue like this;</p>
  
  <pre><code>var value = await response.Content.ReadAsStringAsync();
  var obj = new { message = "", ModelState = new Dictionary&lt;string, string[]&gt;() };
  var x = JsonConvert.DeserializeAnonymousType(value, obj);
  </code></pre>