3

How would I implement retry logic in angular.js with exponential back-off?

  1. Would the right place for the logic be in $httpProvider.requestInterceptors?
  2. Can I selectively pick to use it with some $http services and not others?

2 Answers 2

2

This is an old post, but here's my thoughts. I'd use a responseInterceptor. Since you can just return another promise, you can decide how to retry. You have access the the $http config in the interceptor, so you can add special configuration to determine what the back-off should be (or whether to apply the retry logic at all).

1

For upcoming people: Using some pre available components and module seems more Angular. So you can try one of these backo2 or angular-backoff

There usage is given on each link. However don't use setTimeout its not so Angular and you should use $interval or $timeout.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.