Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .config(['$httpProvider', function ($httpProvider)
- {
- //interceptor for requests and error responses
- $httpProvider.interceptors.push(['$rootScope','$q', '$location', '$localStorage','Auth', function ($rootScope,$q, $location, $localStorage,Auth) {
- return {
- //injecting JWT token into header for requests
- 'request': function (config)
- {
- $rootScope.stateLoading = true;
- config.headers = config.headers || {};
- if ($localStorage.token) {
- config.headers.Authorization = 'Bearer ' + $localStorage.token;
- }
- return config;
- },
- //handling not authorized requests and sending them to the home page.
- 'responseError': function (response)
- {
- $rootScope.stateLoading = false;
- if (response.status === 401 || response.status === 403 || response.status === 400)
- {
- $location.path('/home');
- }
- if(response.status === 498)
- {
- Auth.refresh($localStorage.token).then(function(response)
- {
- $localStorage.token = response.token;
- });
- }
- return $q.reject(response);
- },
- 'response':function(response)
- {
- $rootScope.stateLoading = false;
- return response;
- }
- };
- }]);
- }])
- .config(['ngToastProvider', function(ngToastProvider)
- {
- ngToastProvider.configure({
- animation: 'slide',
- timeout:'5000'
- });
- }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement