$ http.post introduces success function even if Unauthorized status is 403

I have the following code for a login form:

function(loginData) {
    var deferred = $q.defer();
    var data = {
        "email": loginData.email,
        "password": loginData.password,
        "remember": loginData.remember
    };
    $http.post(CONSTANTS.baseURL + '/login', data)
        .success(function(data, status, headers, config) {
            _authenticate(data);
            //redirects to home
            $state.go('home');
            // location.hash = "#/home";
            deferred.resolve(true);
        })
        .error(function(data, status, headers, config) {
            //show error message
            _logout();
            deferred.resolve(false);
            return false;
        });
    return deferred.promise;
};

      

Debugging code always calls the .success function. The request status is 403. The status parameter from .success is also 403

Request Method:POST
Status Code:403 Forbidden

      

+3


source to share


1 answer


I had a similar problem with you, and it turned out that the reason is because I previously configured the $ httpProvider ::

app.config(function ($httpProvider) {
    $httpProvider.interceptors.push('myHttpInterceptor');
});

      



When removing this issue, the error callback was correctly called.

Another link: https://github.com/angular/angular.js/issues/2609

+1


source







All Articles