Nuno_147 Nuno_147 - 4 months ago 40
AngularJS Question

$http success callback is called when an error arrived

I am using AnguarJS $http service to call my server API on an Ionic app.

I am using a code similar to this :

method: 'POST',
url: "url"
}).then(function successCallback(response) {
... handle success operations
}, function errorCallback(error) {
... handle error.

all seems to work perfectly well. when the API is called successfully, the successCallback function is called.

However, when an error like 500 arrived, I am also getting it in the success callback.

I would consider errors to arrive to the errorCallback.


Do you have any http response interceptor (e.g: using $httpProvider.responseInterceptors) setup in your application?

There was a user hitting a very similar issue in GitHub whose issue was an interceptor that didn't reject rejections.

Other users pointed him to this nice GitHub Gist showcasing how to correctly implement a response interceptor: