From af3a35169a585b3d242042f6da7915ac4ea5f755 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Wed, 1 Mar 2017 09:37:37 -0500 Subject: [PATCH] (fix) first pass at CAS XHR issue --- UI/WebServerResources/js/Common/Common.app.js | 38 +++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/UI/WebServerResources/js/Common/Common.app.js b/UI/WebServerResources/js/Common/Common.app.js index ab2302a5e..24ab8d834 100644 --- a/UI/WebServerResources/js/Common/Common.app.js +++ b/UI/WebServerResources/js/Common/Common.app.js @@ -255,15 +255,39 @@ /** * @ngInject */ - ErrorInterceptor.$inject = ['$rootScope', '$q']; - function ErrorInterceptor($rootScope, $q) { + ErrorInterceptor.$inject = ['$rootScope', '$q', '$injector']; + function ErrorInterceptor($rootScope, $q, $injector) { return { responseError: function(rejection) { - if (/^application\/json/.test(rejection.config.headers.Accept)) { - // Broadcast the response error - $rootScope.$broadcast('http:Error', rejection); - } - return $q.reject(rejection); + // Handle CAS ticket renewal + if (rejection.status == -1) { + var iframe = angular.element(''); + iframe.on('load', function() { + var $http = $injector.get('$http'); + + if (rejection.config.method == 'GET') { + return $http({ + method: 'GET', + url: rejection.config.url + }); + } + else if (rejection.config.method == 'POST') { + return $http({ + method: 'POST', + url: rejection.config.url, + data: rejection.data + }); + } + }); + document.body.appendChild(iframe[0]); + } + else { + if (/^application\/json/.test(rejection.config.headers.Accept)) { + // Broadcast the response error + $rootScope.$broadcast('http:Error', rejection); + } + return $q.reject(rejection); + } } }; }