Giovani Barcelos Giovani Barcelos - 3 months ago 7
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

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');
});
Comments