Created
June 25, 2014 17:08
-
-
Save vgdub/425e8cf59dd8e2694e56 to your computer and use it in GitHub Desktop.
http angular inteceptor for loading spinner
This file contains 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
angular.module('matchupApp').config ['$httpProvider', ($httpProvider) -> | |
$httpProvider.interceptors.push ['$log', '$rootScope', ($log, $rootScope) -> | |
requestCount = 0 | |
processIsLoading = (adjustment) -> | |
requestCount += adjustment | |
isStillLoading = requestCount > 0 | |
$rootScope.loading = isStillLoading | |
isStillLoading | |
request = (config) -> | |
processIsLoading 1 | |
config | |
response = (promise) -> | |
processIsLoading -1 | |
promise | |
responseError = (response) -> | |
$log.info 'response', response | |
processIsLoading -1 | |
if response.status = '401' | |
window.location = "/app#/unauthorized" | |
return | |
if response.status = '500' | |
window.location = "/app#/servererror" | |
return | |
window.location = "/app#/unknownerror" | |
response | |
request: request | |
response: response | |
responseError: responseError | |
] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment