Sometimes, the API I'm using will return 200 ok
even though there has been an error. The response JSON object will look something like:
{
error: true
}
I've built a $http response
interceptor that simply checks for this error and rejects it. I want it to then jump into my responseError
function:
$httpProvider.interceptors.push(function($q) {
return {
response: function (response) {
if (response.data.error) {
// There has been an error, reject this response
return $q.reject(response);
}
return response;
},
responseError: function(rejection) {
// Display an error message to the user
...
return $q.reject(rejection);
}
}
});
Problem is, even after rejecting the response, my responseError
function isn't called. It is called on 500
errors etc so I know it's working. I'd expect a rejection to do the same thing.
From the docs:
responseError: interceptor gets called when a previous interceptor threw an error or resolved with a rejection.
Any ideas on what's missing?