title: How to specify message on ajax call to C# webmethod that throws an exception?
body: <p>I have a C# web method that sometimes throws an exception when the call shown below times out (>30 seconds). This is fine I expect this behavior, but the problem is, when the ajax call hits the .fail callback, the error message states "Internal server error". I want to be able to catch the exception and report that the database timed out. How can I do this?</p>
  
  <pre><code>[WebMethod]
  [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
  public static string GetSPResults(string reportId, string sproc, Dictionary&lt;string, string&gt; parameters, string[] ensureArrays, string[] encryptArrays, string[] dateFields)
  {
      ...
          XElement result = avdata.ExecuteSPXmlXElement(sproc, parameters, null);
      ...
  }
  
  $.ajax({
      type: "POST",
      url: "/Patrol/Report.aspx/GetSPResults",
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      data: JSON.stringify(postData)
  }).done(function (result) {
      ...
  }).fail(function (jqXHR, textStatus, err) {
      alert("An error has occurred: " + err); //rerpots "Internal server error" no matter what problem occurs server-side
  });
  </code></pre>