Created
November 7, 2014 16:17
-
-
Save wedgybo/3978c5fc7fb74b43ef24 to your computer and use it in GitHub Desktop.
Network interceptor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.factory('NetworkActivityInterceptor', ['$q', '$injector', function ($q, $injector) { | |
var NetworkActivity; | |
return { | |
request: function (config) { | |
NetworkActivity = $injector.get('NetworkActivity'); | |
if (NetworkActivity.enabled) { | |
var $cordovaNetwork = $injector.get('$cordovaNetwork'); | |
if ($cordovaNetwork.isOffline()) { | |
NetworkActivity.activityOffline(); | |
} else { | |
NetworkActivity.activityStart(); | |
} | |
} | |
return config; | |
}, | |
response: function (response) { | |
NetworkActivity = $injector.get('NetworkActivity'); | |
if (NetworkActivity.enabled) { | |
NetworkActivity.activityStop(); | |
} | |
return response; | |
}, | |
responseError: function (response) { | |
NetworkActivity = $injector.get('NetworkActivity'); | |
if (NetworkActivity.enabled) { | |
NetworkActivity.activityStop(); | |
} | |
return $q.reject(response); | |
} | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment