(fix) first pass at CAS XHR issue

pull/234/head
Ludovic Marcotte 2017-03-01 09:37:37 -05:00
parent 6b471994ef
commit af3a35169a
1 changed files with 31 additions and 7 deletions

View File

@ -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 type="hidden" src="' + UserFolderURL + 'recover"></iframe>');
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);
}
}
};
}