I have a simple AngularJS $http block like so;
$http(req).then(function successCallback(response) {
alert(response);
}, function errorCallback(response) {
alert(response);
});
My issue is that when my ASP.NET Controller returns a HTTP error code, the JS errorCallback receives an object like;
{data: "", status: 304, config: Object, statusText: "Not Modified"}
No matter what I do, I can't seem to populate the data property in my callback.
If instead my controller returns a HTTP OK code, then the 'success' callback is invoked, and the return data is available. But not when it's an error... help!
The controller function is a WebAPI POST handler and looks like;
[System.Web.Http.HttpPost]
public async Task<HttpResponseMessage> Save([FromBody]object data)
{
...<snip>...
return new HttpResponseMessage
{
StatusCode = HttpStatusCode.NotModified,
Content = new JsonContent(JObject.FromObject(new
{
success = false,
message = "User not authorised to perform this action."
}))
};
}
The same construct, but with;
StatusCode = HttpStatusCode.OK
Is successfully received in the success callback in the JS.