Use case for HTTP interceptor requestError

According to http://docs.angularjs.org/api/ng.$http the interceptor has the following methods:

request: function(config) {
  //we could manipulate query here
  return config || $q.when(config);
},
requestError: function(rejection) {
  // what is the use case of this?
  return $q.reject(rejection);
},
response: function(response) {
  // response.status === 200
  return response || $q.when(response);
},
responseError: function(rejection) {
  // when response failed ...
  return $q.reject(rejection);
}

How does it work requestErrorand what use cases can you come up with?

+4
source share
1 answer

One interesting use case is to undo / undo everything that was configured before the request, and would be decided after the response. Examples:

  • loading indicator
  • Overlay
  • disabled form fields

Now that the request cannot be sent or rejected by another interceptor, requestErrorit gives you the opportunity to act accordingly and remove this download indicator or enable form fields.

+3

All Articles