Created
June 2, 2015 14:00
-
-
Save sylouuu/29956ec51d4187e7485c to your computer and use it in GitHub Desktop.
AngularJS Custom HTTP Interceptor
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
app.config(function ($httpProvider) { | |
$httpProvider.interceptors.push('customHttpInterceptor'); | |
}); |
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
app.factory('customHttpInterceptor', function ($q) { | |
return { | |
// HTTP request success | |
request: function (config) { | |
return config; | |
}, | |
// HTTP request error | |
requestError: function (response) { | |
return $q.reject(response); | |
}, | |
// HTTP response success | |
response: function (response) { | |
return response; | |
}, | |
// HTTP response error | |
responseError: function (response) { | |
return $q.reject(response); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment