Skip to content

Instantly share code, notes, and snippets.

@nicovalencia
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicovalencia/ec2f734441062fc9c007 to your computer and use it in GitHub Desktop.
Save nicovalencia/ec2f734441062fc9c007 to your computer and use it in GitHub Desktop.
Add global timeout to Angular $http
/**
* @monkeypatch
* $http gives us no way to add a global timeout default. This is critical
* for triggering the YOUR_FAULT_TOLERANCE module to handle timeouts after
* a reasonable amount of time:
*
* @upgrade instructions
* Ensure that arguments[x] is overriding the timeout property of the
* $httpBackend provider's constructor.
*
* source: https://github.com/angular/angular.js/blob/master/src/ng/httpBackend.js#L31
*/
.config(function($provide) {
$provide.decorator('$httpBackend', function($delegate) {
return function (splat) {
if (typeof timeout === 'undefined') {
arguments[5] = 3000; // Default timeout in milliseconds
}
return $delegate.apply($delegate, arguments);
}
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment