I'm kind of new to ajax so please excuse my ignorance.
In AngularJs, I make an ajax post like so:
$.ajax({
url: "http://localhost:65337/api/Account/Register",
type: "POST",
beforeSend: function (request) {
request.setRequestHeader("Authorization", "Bearer " + $scope.authToken);
request.setRequestHeader("Content-Type", "application/json; charset=utf-8");
},
datatype: "json",
data: JSON.stringify(postObj)
}).error(function (data, status, error) {
$scope.$emit('MESSAGE', data.Message, data.IsError);
}).success(function (xmlHttpRequest, status, error) {
// this callback fires even on server error code 500
})
and I am trying to get the above error callback to fire when I encounter an internal error on my server, when server encounters an error, I send the following response:
var response = new HttpResponseMessage(HttpStatusCode.InternalServerError);
ErrorTModel data = new ErrorTModel(msg, IsError);
response.Content = new StringContent(
JsonConvert.SerializeObject(data,
Formatting.Indented,
new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }),
Encoding.UTF8,
"application/json"
);
return response;
I've read everything I can find on google regarding this matter so any assistance would be greatly appreciated.