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

Bad state: Can't finalize a finalized Request.

jlubeck opened this issue · comments

I just got a chance to try this out, and the first time that I got my request to try, I got this exception:

Bad state: Can't finalize a finalized Request.

This is how I'm creating my initial client:

    var httpClient = HttpClientWithInterceptor.build(
        retryPolicy: ApiRetryPolicy(), interceptors: []);

And this is my RetryPolicy

class ApiRetryPolicy extends RetryPolicy {
  @override
  int maxRetryAttempts = 1;

  @override
  Future<bool> shouldAttemptRetryOnResponse(ResponseData response) async {
    if (response.statusCode == 302) {
      // Auth expired. Re-login and try again
      if (CurrentUser().email != null && CurrentUser().password != null) {
        var loginResults = await AuthenticationService.login(
            email: CurrentUser().email, password: CurrentUser().password);
        if (loginResults.isAuthorized) {
          CurrentUser().oAuth = loginResults.oAuth;
          // Re-try request
          return true;
        }
      }
    }
    return false;
  }
}

Will look into this ASAP.

Thanks for the issue!

Definitely a bug in need of a fix. Hopefully a patch version will come out this week for this issue. Thanks!

Might be related to resending the same request. Note to self on this SO post that might help come up with a solution.

Nice! Doesn't seem like 0.4.1 has this fix yet though, unless I'm missing something?

Hi, thanks for writing. Not just yet since I'm working on adding testing and a stable 1.0.0 release. It will involve breaking changes so I'm trying to be as thorough as I can be. In the meantime if you want I can try to isolate the change and release another patch version if that's ok.

That's fine, I can wait since this wasn't really a breaking issue. Thanks!

Hi, a patch version would be great indeed!

I will try to have by the weekend ✌🏼🙌🏼

Screen Shot 2021-07-27 at 10 51 07 AM

http_interceptor: ^1.0.1
please any update for this issue !???

Hi, thanks for writing. This should have been fixed with 1.0.0

Can you give me a bit more of an explanation as to what you are trying to do? I want to figure out the cause of your situation since it's affecting the fix made earlier and fix the root cause. 😊

Hi, thx for your reponse, i am trying to refresh my token, when i have 401 error i call my endpoint to refresh the token and i make retryPolicy in http to call the endpoint again, if you have example for retryPolicy share me please because i don t find in documentation
Thank you

Can you tell me or setup a repository where I can reproduce this?

I have tried to make it fail but couldn't, maybe I am doing something differently.

So, please share me your code, maybe my logic is wrong
thank you