SecurityInterceptor

来自ling
跳转至: 导航搜索
MetronicApp.factory('securityInterceptor', function ($rootScope) {
    return {
        'request': function (config) {
            if (config.url.split('?')[0].endsWith(".ljson")) {
                if (config.quiet) {
                    $rootScope.quietAppLoading = true;
                } else {
                    $rootScope.appLoading = true;
                }
            }
            return config;
        },
        'response': function (response) {
            if (response.config.url.split('?')[0].endsWith(".ljson")) {
                $rootScope.appLoading = false;
                $rootScope.quietAppLoading = false;
            }
            return response;
        },
        'requestError': function (rejection) {
            if (rejection.config.url.split('?')[0].endsWith(".ljson")) {
                $rootScope.appLoading = false;
                $rootScope.quietAppLoading = false;
            }
            return rejection;
        },
        'responseError': function (rejection) {
            if (rejection.config.url.split('?')[0].endsWith(".ljson")) {
                $rootScope.appLoading = false;
                $rootScope.quietAppLoading = false;
            }
            if (rejection.status == 401) {
                window.location.href = path + "pages/onLineShop/index.html";
            } else {
                return rejection;
            }
            return rejection;
        }
    };
});