2018-02-10 15:18:01 +00:00
|
|
|
import ngModule from '../module';
|
2018-05-25 15:25:35 +00:00
|
|
|
import HttpError from './http-error';
|
2017-06-05 07:01:21 +00:00
|
|
|
|
2018-05-25 15:25:35 +00:00
|
|
|
interceptor.$inject = ['$q', 'vnApp', '$cookies'];
|
|
|
|
function interceptor($q, vnApp, $cookies) {
|
2017-06-05 07:01:21 +00:00
|
|
|
return {
|
|
|
|
request: function(config) {
|
2017-11-16 12:47:18 +00:00
|
|
|
vnApp.pushLoader();
|
2017-06-05 07:01:21 +00:00
|
|
|
let token = $cookies.get('vnToken');
|
|
|
|
|
|
|
|
if (token)
|
|
|
|
config.headers.Authorization = token;
|
|
|
|
|
|
|
|
return config;
|
|
|
|
},
|
|
|
|
requestError: function(rejection) {
|
|
|
|
return $q.reject(rejection);
|
|
|
|
},
|
|
|
|
response: function(response) {
|
2017-11-16 12:47:18 +00:00
|
|
|
vnApp.popLoader();
|
2017-06-05 07:01:21 +00:00
|
|
|
return response;
|
|
|
|
},
|
|
|
|
responseError: function(rejection) {
|
2017-11-16 12:47:18 +00:00
|
|
|
vnApp.popLoader();
|
2018-05-25 15:25:35 +00:00
|
|
|
let err = new HttpError(rejection.statusText);
|
|
|
|
Object.assign(err, rejection);
|
|
|
|
return $q.reject(err);
|
2017-06-05 07:01:21 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2018-02-10 15:18:01 +00:00
|
|
|
ngModule.factory('vnInterceptor', interceptor);
|