title: Returning JSON Errors from Asp.Net MVC 6 API
body: <p>I'm trying out building a web API with MVC 6.  But when one of my controller methods throws an error, the content of the response is a really nicely formatted HTML page that would be very informative were this an MVC app.  But since this is an API, I'd rather have some JSON returned instead.  </p>
  
  <p>Note:  My setup is super basic right now, just setting:</p>
  
  <pre><code>    app.UseStaticFiles();
      app.UseIdentity();
  
      // Add MVC to the request pipeline.
      app.UseMvc();
  </code></pre>
  
  <p>I want to set this up universally. Is there a "right/best" way to set this up in MVC 6 for an API?  </p>
  
  <p>Thanks...</p>