Before updating this apiPost method using $.post successfully handles fail (a HTTPResponseMessage with a 401 Status Code is returned from the api call) (failure and always are undefined in apiPost method calling code).
self.modelIsValid = ko.observable(true);
self.modelErrors = ko.observableArray();
self.apiPost = function (uri, data, success, failure, always) {
self.isLoading(true);
self.modelIsValid(true);
$.post(rootPath + uri, data)
.done(success)
.fail(function (result) {
if (failure == null) {
if (result.status != 400)
self.modelErrors([result.status + ':' +
result.statusText + ' - ' + result.responseText]);
else
self.modelErrors(JSON.parse(result.responseText));
self.modelIsValid(false);
}
else
failure(result);
})
.always(function () {
if (always == null)
self.isLoading(false);
else
always();
});
};
When stepping through the code the fail code block is hit and then dozens of lines of jquery, javascript, knockout and VM extension code is run before returning to the fail code block and the inner if and updating the modelErrors array and then setting the modelIsValid to false.
After updating the fail block is hit and the other code is then run but it never returns to the fail code block. The array never gets updated and the modelIsValid is never set to false (a ValidationError partial view is triggered by modelIsValid being false).
Original versions: jquery -1.9.1 and knockout-2.2.1.
Updated versions: jquery -3.1.1 and knockout-3.4.2.
Running on Widnows 7 Ultimate, VS2015 and the lastest Chrome. Debugging the javascript in Developer Tools.
Has something changed in jquery or knockout that breaks the fail. How would I rewrite to fix the problem?