Giovani Barcelos Giovani Barcelos - 1 year ago 44
AngularJS Question

AngularJS $http won't fire second .then function

I have this piece of code where the response status code is 403. The problem is it will never fire the second function, it simply does nothing.

I've seen similar errors but people were using interceptors, which I'm not.

Itens.signUp($scope.user, confirmation).then(function (response) {
console.log('success');
},
function (response) {
console.log('error');
});

Answer Source

The below isn't formatted right.

.then(function(response) {
    console.log('success');
  }),
  function(response) {
    console.log('error');
  };
}

It should be like this:

.then(function(response) {
  console.log('success');
}, function(response) {
  console.log('error');
});

Alternatively you could also do this:

.then(function () {
  console.log('success');
})
.catch(function () {
  console.log('error');
});