resurtm

Untitled

Jan 6th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         /* @ngInject */
  2.         $httpProvider.interceptors.push(function ($rootScope, $q, localStorageService) {
  3.             return {
  4.                 request: function (config) {
  5.                     config.headers = config.headers || {};
  6.                     var authToken = getAuthToken();
  7.                     if (authToken) {
  8.                         config.headers.Authorization = 'Bearer ' + authToken;
  9.                     }
  10.                     return config;
  11.                 },
  12.  
  13.                 responseError: function (rejection) {
  14.                     if (!rejection.config.ignoreAuthModule) {
  15.                         switch (rejection.status) {
  16.                             case 401:
  17.                                 $rootScope.$broadcast('event:auth-login-required', rejection);
  18.                                 break;
  19.                             case 403:
  20.                                 $rootScope.$broadcast('event:auth-forbidden', rejection);
  21.                                 break;
  22.                         }
  23.                     }
  24.                     return $q.reject(rejection);
  25.                 }
  26.             };
  27.         });
Advertisement
Add Comment
Please, Sign In to add comment