2015-06-30 16:15:16 +00:00
|
|
|
'use strict';
|
2015-06-29 22:51:29 +00:00
|
|
|
|
2015-06-30 11:05:44 +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-01 23:14:39 +00:00
|
|
|
if( $location.path() !== '/users/me' ){
|
|
|
|
|
|
|
|
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-06-30 19:42:02 +00:00
|
|
|
}
|
|
|
|
return $q.reject(response);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}]);
|
2015-06-29 22:51:29 +00:00
|
|
|
|
|
|
|
|
2015-06-30 19:42:02 +00:00
|
|
|
// Config HTTP Error Handling
|
|
|
|
// angular.module('users').config(['$httpProvider',
|
|
|
|
// function($httpProvider) {
|
|
|
|
// // Set the httpProvider "not authorized" interceptor
|
|
|
|
// $httpProvider.interceptors.push(['$q', '$location', 'Principal',
|
|
|
|
// function($q, $state, Principal) {
|
|
|
|
// return {
|
|
|
|
// responseSuccess: function(response) {
|
|
|
|
// Principal.identity().then(function(user){
|
|
|
|
// console.log(user);
|
|
|
|
// // $rootScope.user = user;
|
|
|
|
// }, function(error){
|
|
|
|
// console.log("Coudn't get current user. \n ERROR: "+error);
|
|
|
|
// });
|
|
|
|
|
|
|
|
// },
|
|
|
|
// responseError: function(rejection) {
|
|
|
|
// switch (rejection.status) {
|
|
|
|
// case 401:
|
|
|
|
// // Deauthenticate the global user
|
|
|
|
// Principal.authenticate(null);
|
|
|
|
|
|
|
|
// // Redirect to signin page
|
|
|
|
// $location.path('/signin');
|
|
|
|
// break;
|
|
|
|
// case 403:
|
|
|
|
// // Add unauthorized behaviour
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return $q.reject(rejection);
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
// }
|
|
|
|
// ]);
|
|
|
|
// }
|
|
|
|
// ]);
|