title: .NET web API exception error details
body: <p>I'm really new to web APIs and was experimenting on some API controllers exceptions. My problem here is when an exception is thrown, the application will return too much information which would include the stacktrace and some properties of the model being returned. I was wondering if the exceptions returned can be limited to just a message?</p>
  
  <p>Here's an example:</p>
  
  <pre><code>public IEnumerable&lt;Appointments&gt; GetAll(int id)
  {
      IEnumerable&lt;Appointments&gt; appointments = icdb.Appointments.Where(m =&gt; m.Id== id).AsEnumerable();
      return appointments;
  }
  </code></pre>
  
  <p>And if this would return an exception (diff issue), it would return something like this:</p>
  
  <blockquote>
    <p>{"Message":"An error has occurred.","ExceptionMessage":"The
    'ObjectContent`1' type failed to serialize the response body for
    content type 'application/json;
    charset=utf-8'.","ExceptionType":"System.InvalidOperationException","StackTrace":null,"InnerException":{"Message":"An
    error has occurred.","ExceptionMessage":"Self referencing loop
    detected for property 'UpdateBy' with type
    'System.Data.Entity.DynamicProxies.User_B23589FF57A33929EC37BAD9B6F0A5845239E9CDCEEEA24AECD060E17FB7F44C'.
    Path
    '[0].UpdateBy.UserProfile.UpdateBy.UserProfile'.","ExceptionType":"Newtonsoft.Json.JsonSerializationException","StackTrace":..................................
              :
              :
              : }</p>
  </blockquote>
  
  <p>As you noticed, it would return a stacktrace with most of the properties of my model. Is there a way where I can just return a message when an exception is thrown?</p>