I am on the look out for an accepted solution for trapping errors in the following scenario: i have an asp.net web services that interacts with the database. I interact with the web service through jquery's $ajax function.
I would like to know what is the accepted stable methodology for error trapping. When the data is received from the the web service there are two types of errors in my scenario:
- db errors
- ajax errors
Ajax errors can trapped inside error portion of $ajax function. I trap the database errors inside the web service and so far I could only come up with one idea how to pass them on to the user - pack them in the results array. But this solution is awkward. Are there any better ideas?
Here is the sample of code I use for accessing asp.net web service:
$.ajax({
type: "POST",
url: "http://localhost/WebServices/Service.asmx/GetBillingEntities",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response) {
var results = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
DisplayResults();
},
error: function(xhr, status, error) {
// Display a generic error for now.
alert("AJAX Error!");
}
});
So should the database results go in to results array and unpacked there manually? Is there a better system? Thanks!