Reputation: 1044
I have an AngularJS application with an interceptor to display error messages.
Sometimes the error message from the backend needs some front-end treatment to give more context, like changing a "access denied" into "You can't do this because of X".
How can I do this so the interceptor does not get called?
Right now I am endind up with 2 messages. The message from my controller and the message from the interceptor.
Upvotes: 0
Views: 327
Reputation: 1044
Solution:
service.js:
myFunction: function(id) {
return $http.post('myUrl/', {}, {skipErrorInterceptor: true});
}
interceptor.js:
'responseError': function(rejection) {
if (rejection.config.skipErrorInterceptor) {
return $q.reject(rejection);
} else {
... Global message treatment
}
return $q.reject(rejection);
}
Upvotes: 1