2015-06-30 06:12:32 +00:00
|
|
|
'use strict';
|
2015-06-29 22:51:29 +00:00
|
|
|
|
2015-06-30 06:12:32 +00:00
|
|
|
// Config HTTP Error Handling
|
2015-06-30 17:36:51 +00:00
|
|
|
angular.module('users').config(['$httpProvider',
|
|
|
|
function($httpProvider) {
|
2015-06-30 19:42:02 +00:00
|
|
|
$httpProvider.interceptors.push(function($q, $location) {
|
|
|
|
return {
|
|
|
|
responseError: function(response) {
|
2015-07-28 22:29:07 +00:00
|
|
|
// console.log($location.path());
|
2015-11-03 20:51:22 +00:00
|
|
|
if( $location.path() !== '/users/me' && $location.path() !== '/forms' && response.config){
|
2015-11-03 20:53:42 +00:00
|
|
|
if(response.config.url !== '/users/me' && response.config.url !== '/forms'){
|
2015-08-06 05:52:59 +00:00
|
|
|
console.log('intercepted rejection of ', response.config.url, response.status);
|
|
|
|
if (response.status === 401) {
|
|
|
|
// save the current location so that login can redirect back
|
|
|
|
$location.nextAfterLogin = $location.path();
|
|
|
|
$location.path('/signin');
|
|
|
|
}else if(response.status === 403){
|
|
|
|
$location.path('/access_denied');
|
|
|
|
}
|
2015-07-01 23:14:39 +00:00
|
|
|
}
|
|
|
|
|
2015-06-30 19:42:02 +00:00
|
|
|
}
|
|
|
|
return $q.reject(response);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
2015-07-09 22:21:29 +00:00
|
|
|
}]);
|