panel.js.promise-tracker-http-interceptor.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of splout-server Show documentation
Show all versions of splout-server Show documentation
Splout SQL is a read only, horizontally scalable and
partitioned SQL database that plays well with Hadoop.
The newest version!
/*
* promise-tracker - v2.0.1 - 2014-04-11
* http://github.com/ajoslin/angular-promise-tracker
* Created by Andy Joslin; Licensed under Public Domain
*/
(function() {
angular.module('ajoslin.promise-tracker')
.config(['$httpProvider', function($httpProvider) {
$httpProvider.interceptors.push(['$q', 'promiseTracker', function($q, promiseTracker) {
return {
request: function(config) {
if (config.tracker) {
if (!angular.isArray(config.tracker)) {
config.tracker = [config.tracker];
}
config.$promiseTrackerDeferred = config.$promiseTrackerDeferred || [];
angular.forEach(config.tracker, function(tracker) {
var deferred = tracker.createPromise();
config.$promiseTrackerDeferred.push(deferred);
});
}
return $q.when(config);
},
response: function(response) {
if (response.config && response.config.$promiseTrackerDeferred) {
angular.forEach(response.config.$promiseTrackerDeferred, function(deferred) {
deferred.resolve(response);
});
}
return $q.when(response);
},
responseError: function(response) {
if (response.config && response.config.$promiseTrackerDeferred) {
angular.forEach(response.config.$promiseTrackerDeferred, function(deferred) {
deferred.reject(response);
});
}
return $q.reject(response);
}
};
}]);
}]);
}());