Created
April 15, 2016 15:03
-
-
Save TiagoWinehouse/08e9c836e45a07869ec47e8662521451 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.factory(SecurityHttpInterceptor, 'SecurityHttpInterceptor') | |
SecurityHttpInterceptor.$inject = ['$q']; | |
function SecurityHttpInterceptor($q) { | |
console.log("Entrou") | |
return function (promise) { | |
console.log(promise) | |
return promise.then(function (response) { | |
console.log(response.status) | |
return response; | |
}, | |
function (response) { | |
console.log(response.status) | |
if (response.status === 500) { | |
//$state.go('app.errorapi'); | |
} | |
return $q.reject(response); | |
}); | |
}; | |
}; | |
$httpProvider.interceptors.push(function ($q, $rootScope, $location) { | |
return { | |
'responseError': function (rejection) { | |
var status = rejection.status; | |
var config = rejection.config; | |
var method = config.method; | |
var url = config.url; | |
console.log(status) | |
console.log(config) | |
console.log(method) | |
console.log(url) | |
if ((status >= 500) && (status < 600)) { | |
$location.path("/ErrorAPI"); | |
} else { | |
$location.path("/ErrorAPI"); | |
$rootScope.error = method + " on " + url + " failed with status " + status; | |
} | |
return $q.reject(rejection); | |
} | |
}; | |
}); | |
$httpProvider.interceptors.push(function ($q, $rootScope, $location) { | |
return { | |
'request': function (config) { | |
//if (angular.isDefined($rootScope.authToken)) { | |
// var authToken = $rootScope.authToken; | |
// config.headers['X-Auth-Token'] = authToken; | |
//} | |
return config || $q.when(config); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment