CodingAleCR / http_interceptor

A lightweight, simple plugin that allows you to intercept request and response objects and modify them if desired.
MIT License
134 stars 67 forks source link

Http Retry Policy not working #27

Closed EricDatis closed 4 years ago

EricDatis commented 4 years ago

shouldAttemptRetryOnResponse never triggered

class ExpiredTokenRetryPolicy extends RetryPolicy {
  @override
  bool shouldAttemptRetryOnResponse(http.Response response) {
    log('TESTTSTSTS' + response.statusCode.toString());
    if (response.statusCode == 401) {
      return true;
    }
    return false;
  }
}
static http.Client client = HttpClientWithInterceptor
    .build(
      interceptors: [ApiInterceptor()],
      retryPolicy: ExpiredTokenRetryPolicy()
    );
static Future<List<Event>> getEvents() async {
    var url = baseUrl + "/event";
    return client.get(url, headers: API.headers)
      .then((response) {
        Iterable list = json.decode(response.body)['data']['events'];
        return list.map((model) => Event.fromJson(model)).toList();
      })
      .catchError((err) {
        log('error: $err');
      });
  }

I'm using dart for apps

issue-label-bot[bot] commented 4 years ago

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.88. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

CodingAleCR commented 4 years ago

Hi @EricDatis I will double check this and make sure I can reproduce it. Will get back to you ASAP. Thanks for opening an issue for this. ✌🏼

CodingAleCR commented 4 years ago

Just letting you know about my findings @EricDatis. Seems like there is a bug with the way we are handling the retry count inside a client. I have fixed it and it will be available on the #32 release. 👋🏼