-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
/
http.js
32 lines (26 loc) · 981 Bytes
/
http.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(function ($) {
var httpInterceptors = angular.module('httpInterceptors', []);
httpInterceptors.factory('httpInterceptor', function ($q) {
return {
'request': function (config) {
var t = new Date().getTime();
if (config.url.indexOf('.htm') != -1 || config.url.indexOf('?_=') != -1) {
return config;
}
config.url = config.url + '?_=' + t;
return config;
},
'response': function (response) {
if (typeof response.data === 'object') {
if (response.data.code != null && response.data.code != 200) {
return $q.reject(response);
}
}
return response;
}
};
});
httpInterceptors.config(function ($httpProvider) {
$httpProvider.interceptors.push('httpInterceptor');
});
})(jQuery);