CodingAleCR / http_interceptor

A lightweight, simple plugin that allows you to intercept request and response objects and modify them if desired.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Retry Policy with delay

ntimesc opened this issue · comments

commented

Not sure, how to configure or implement Retry Policy with a delay. Currently, I am using RetryPolicy for refresh token but would like to extend its usage by handling the no internet connectivity retry and for that i am trying to capture the exception in this function shouldAttemptRetryOnException and returning true. However, this function immediately tries 3 attempts back to back without any delay. So would like to know what how can I add a delay in between or is there anything in http_interceptor to configure delays between requests.


import 'package:http_interceptor/http_interceptor.dart';

class RefreshAndRetryTokenPolicy extends RetryPolicy {
  @override
  int get maxRetryAttempts => 3;

   @override
   bool shouldAttemptRetryOnException(Exception reason)  {
     print('Exception in policy  $reason');

   
    //when no internet connection encountered, allow user to retry the same request

     return true;
   }

  @override
  Future<bool> shouldAttemptRetryOnResponse(ResponseData response) async {
   
    //currently handling refresh token successfully
	
    return true;
  }
}

Hi, I think there's no way to asynchronously wait a few seconds before retrying at the moment.

This makes me think I should make shouldAttemptRetryOnException into a Future<bool> so that it supports this kind of behaviors and then you could maybe use Future.delayed in these cases (that might make the request stay "loading" until it is either resolved or rejected, which is something to look out for).

commented

Hi, I think there's no way to asynchronously wait a few seconds before retrying at the moment.

This makes me think I should make shouldAttemptRetryOnException into a Future<bool> so that it supports this kind of behaviors and then you could maybe use Future.delayed in these cases (that might make the request stay "loading" until it is either resolved or rejected, which is something to look out for).

So when can we have this feature available :)

It should be available in beta.6, which is already in the automation pipeline as I'm writing this.

It's now out 🎉 I'm closing this but feel free to comment if it does not work as you expected 😉