How to use angularJS interceptor to only intercept specific http requests?

前端 未结 7 568
耶瑟儿~
耶瑟儿~ 2020-12-23 21:17

I know how to intercept ALL requests, but I only want to intercept requests from my resources.

Does anyone know how to do this?

services.config([\'$h         


        
7条回答
  •  借酒劲吻你
    2020-12-23 21:43

    I know it is an old question but I wanted to provide a solution if you have pushed multiple $http Interceptors and want them to continue working, return your response so the Interceptor chain continues:

        module.factory('resourceInterceptor', ['$q', function($q) {
            return {
                response: function(response) {
                    // do your conditional logic here
                    if (...) {
                        return $q.resolve(response);
                    }
                },
                responseError: function(response) {
                    // do your conditional logic here   
                    if (...) {
                        return $q.reject(response);
                    }
                }
            };
        }]);
    

提交回复
热议问题