Last active
August 29, 2015 14:10
-
-
Save nicovalencia/ec2f734441062fc9c007 to your computer and use it in GitHub Desktop.
Add global timeout to Angular $http
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
/** | |
* @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