1

I am very new to the angularjs, basically i want to check all $http request with angularjs interceptor and if the response data match 401 then redirect to login page

Any help appreciated

2
  • Which version are you using? Commented Mar 7, 2017 at 22:03
  • @vinagreti Sorry about that ... It is angular version 1.5 Commented Mar 7, 2017 at 22:13

1 Answer 1

2

You can find more details on interceptors here.

In short, you can put following code in config section of your main module.

$httpProvider.interceptors.push(function($q, dependency1, dependency2) {
  return {
    response: function(response){
      return promise.then(
        function success(response) {
        return response;
      },
      function error(response) {
        if(response.status === 401){
          //your redirection code goes here 
          return $q.reject(response);
        }
        else{
          return $q.reject(response); 
        }
      });
    }
  }
});
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.