Custom json response body for HTTP errors
<p>I'm wondering if there is a way in API Controllers to return a custom object as response body for methods like: <code>BadRequest()</code> or <code>NotFound()</code>.</p>

<p>For example, for <strong>404</strong> error, I'd like to return something like:</p>

<pre><code>{
  "StatusCode": 404,
  "Error": "Not Found",
  "Message": "Custom message..."
}
</code></pre>

<p>Instead I'm getting this:</p>

<pre><code>{
  "Message": "Custom message..."
}
</code></pre>

<p>At the moment to return complex response body I'm using <code>Ok()</code> this way:</p>

<pre><code>return Ok(new
{
    Success = false,
    Message = "Custom message...",
    // other fields...
});
</code></pre>

<p>But obviously I'm returning a <strong>200</strong> status that is not so meaningful.</p>

<p>Is there a better way to achieve this?</p>