Interceptor not working

后端 未结 1 373
我寻月下人不归
我寻月下人不归 2020-12-06 06:14

Im trying to make a Interceptor in AngularJS. I\'m quite new to AngularJS and found some examples of Interceptor, but can\'t get it to work.

Here I have my app.js fi

相关标签:
1条回答
  • 2020-12-06 07:03

    $httpProvider.responseInterceptors are deprecated. You can modify your code

    app.factory('errorInterceptor', ['$q', '$rootScope', 'MessageService', '$location',
        function ($q, $rootScope, MessageService, $location) {
            return {
                request: function (config) {
                    return config || $q.when(config);
                },
                requestError: function(request){
                    return $q.reject(request);
                },
                response: function (response) {
                    return response || $q.when(response);
                },
                responseError: function (response) {
                    if (response && response.status === 404) {
                    }
                    if (response && response.status >= 500) {
                    }
                    return $q.reject(response);
                }
            };
    }]);
    
    app.config(['$httpProvider', function ($httpProvider) {
        $httpProvider.interceptors.push('errorInterceptor');    
    }]);
    

    See Docs for more info

    0 讨论(0)
提交回复
热议问题