Fixing a Broken Interceptor
Web Development
1
Posts
1
Posters
1
Views
1
Watching
-
We're developing a Angular 1 site that talks to a .NET WebAPI2 api. We have an interceptor related to the authentication side, but we're having problems with it. We are using a loading bar Angular component, and that component is reporting that the interceptor is broken. But we're not sure where/why and worse where to start investigating. By simple code elimination, the _request method seems to be ok (or at least doesn't cause issues, it might still be bad code!) Its the _responseSuccess method that causes the problem.
'use strict';
app.factory('authInterceptorService', ['$injector', '$q', '$location', 'localStorageService', function ($injector, $q, $location, localStorageService)
{var authInterceptorServiceFactory = {}; function RequiresRefresh(responseURL) { if (responseURL.indexOf('getcutofftime') > -1) return false; if (responseURL.indexOf('resources') !== -1) return true; return false; } var \_request = function (config) { config.headers = config.headers || {}; var authData = localStorageService.get('authorizationData'); if (authData) { config.headers.Authorization = 'Bearer ' + authData.token; } return config || q$.when(config); }; //should handle all error responses in here. //var \_responseError = function (rejection) //{ // console.log("Intercepted Rejection: " + rejection); // return $q.reject(rejection); //}; var \_responseSuccess = function (response) { var responseURL = response.config.url; if (responseURL !== null && typeof responseURL !== 'undefined') { //check to make sure it's actually an interaction with the resourcesAPI - these are the only times it should refresh the token. if (RequiresRefresh(responseURL)) { //get a new token! var authData = localStorageService.get('authorizationData'); var JSONdata = { windowsFullName: authData.windowsFullName , windowsUserName: authData.windowsUserName , summitUserName: authData.summitUserName , summitFullName: authData.summitFullName , clientID: 'MatterhornAuthApp' }; $injector.get("$http") .post(serviceBase + 'usermanagement/account/ReissueToke