1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-10 06:08:34 +02:00
bitwarden-browser/src/app/apiInterceptor.js

29 lines
1.1 KiB
JavaScript
Raw Normal View History

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);
}
};
});