title: 'return BadRequest' ignores ExceptionFilter
body: <p>The subject pretty much sums it up. I have an ExceptionFilter which forces developers in the project to throw only one type of exception which it allows through, any other exception is converted to a generic 500 exception. Whenever a WebApi controller method does 'return BadRequest('some message')' however, it doesn't go through the exception filter.</p>
  
  <p>The problem is that I have to adhere to a specification in creating the Api. The specification states that things like BadRequest (and other http error states) have to have a custom json message in the response. Throwing an exception works, but returning a BadRequest doesn't. Any ideas around this?</p>
  
  <p>ps. I know I can do this in an ActionFilter, but that feels awkward, generating exception responses in two places.</p>
  
  <p>Simple test example from my controller. (doesn't do anything useful but reproduces the problem). Whenever I call this method with a value higher than 100 it returns a bad request and doesn't go through my ExceptionFilter:</p>
  
  <pre><code>[HttpGet]
  [Route("values/{count}")]
  public async Task&lt;IHttpActionResult&gt; GetValues(int count)
  {
    int max = 100;
  
    if (count &gt; max)
    {
      return BadRequest("'count' exceeded the maximum value of " + max);
    }
  
    var result = new List&lt;string&gt;();
  
    for (int i = 0; i &lt; count; i++)
    {
      result.Add(Guid.NewGuid().ToString("n"));
    }
  
    return Ok(result);
  }
  </code></pre>
  
  <p>This code DOES go through the ExceptionFilter (and is converted to a generic 500):</p>
  
  <pre><code>[HttpGet]
  [Route("unhandledexception/{httpError}")]
  public void UnhandledException(int httpError)
  {
    throw new Exception("This is a thrown exception for testing purposes with http code " + httpError);
  }
  </code></pre>
  
  <p>This ALSO goes through the ExceptionFilter (and there it serializes to my custom json):</p>
  
  <pre><code>[HttpGet]
  [Route("handledexception/{httpError}")]
  public void HandledException(int httpError)
  {
    var error = new CustomApplicationError(httpError, 
      "Handled exception! Your input or request was wrong, " +
      "or something else, and now I'm telling you about it!");
  
    throw new HandledException(httpError, error, Request);
  }
  </code></pre>
  
  <p>ExceptionFilter:</p>
  
  <pre><code>public override Task OnExceptionAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken)
  {
    var task = base.OnExceptionAsync(actionExecutedContext, cancellationToken);
  
    return task.ContinueWith((t) =&gt;
    {
      var handledException = actionExecutedContext.Exception as HandledException;
  
      if (handledException != null)
      {
        // &lt;snip&gt; serialize and set to response
      }
      else
      {
        // &lt;snip&gt; create generic 500 and set to response
      }
    });
  }
  </code></pre>