code: function responseError(response) {
        if (response.status === 401) {
          // remove any stale tokens
          $cookieStore.remove('token');
  
          // use timeout to perform location change
          // in the next digest cycle
          $timeout(function () {
            $location.path('/login');
          }, 0);
  
          return $q.reject(response);
        }
        return $q.reject(response);
      }
docs: Intercept 401s and redirect you to login