2015-12-09 04:35:05 +01:00
|
|
|
angular
|
|
|
|
.module('bit')
|
|
|
|
|
|
|
|
.factory('apiInterceptor', function ($injector, $q, toastr) {
|
|
|
|
return {
|
|
|
|
request: function (config) {
|
|
|
|
return config;
|
|
|
|
},
|
|
|
|
response: function (response) {
|
2016-09-18 05:00:05 +02:00
|
|
|
if (response.status === 401 || response.status === 403) {
|
2015-12-09 04:35:05 +01:00
|
|
|
$injector.get('authService').logOut();
|
|
|
|
$injector.get('$state').go('frontend.login.info').then(function () {
|
|
|
|
toastr.warning('Your login session has expired.', 'Logged out');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return response || $q.when(response);
|
|
|
|
},
|
|
|
|
responseError: function (rejection) {
|
2016-09-18 05:00:05 +02:00
|
|
|
if (rejection.status === 401 || rejection.status === 403) {
|
2015-12-09 04:35:05 +01:00
|
|
|
$injector.get('authService').logOut();
|
|
|
|
$injector.get('$state').go('frontend.login.info').then(function () {
|
|
|
|
toastr.warning('Your login session has expired.', 'Logged out');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return $q.reject(rejection);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|