title: Get custom validation error message from Web Api request to HttpClient
body: <p>I have the following model for my ASP.NET Web Api 2 service:</p>
  
  <pre><code>public class Message
  {
      public int Id { get; set; }
  
      [Required]
      [StringLength(10, ErrorMessage = "Message is too long; 10 characters max.")]
      public string Text { get; set; }
  }
  </code></pre>
  
  <p>I am making the request from my WinForms app:</p>
  
  <pre><code>using (var client = new HttpClient())
  {
      client.BaseAddress = new Uri(BaseAddress);
      client.DefaultRequestHeaders.Accept.Clear();
      client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  
      var messageOverTenCharacters = new Message { Text = "OverTenCharacters" }
  
      var response = await client.PostAsJsonAsync("api/messenger/PushMessage", messageOverTenCharacters);
  
      // How do I see my custom error message that I wrote in my model class?
  }
  </code></pre>
  
  <p>How do I see my custom error message that I wrote in my model class?</p>
  
  <p>Here is my implementation for my validation class that I'm registering to the web api config:</p>
  
  <pre><code>public class ValidateModelAttribute : ActionFilterAttribute
  {
      public override void OnActionExecuting(HttpActionContext actionContext)
      {
          if (actionContext.ModelState.IsValid == false)
          {
              actionContext.Response = actionContext.Request.CreateErrorResponse(
                  HttpStatusCode.BadRequest, actionContext.ModelState);
          }
      }
  }
  </code></pre>