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

Bad state: Can't finalize a finalized Request. #50

Closed jlubeck closed 3 years ago

jlubeck commented 3 years ago

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;
  }
}
CodingAleCR commented 3 years ago

Will look into this ASAP.

Thanks for the issue!

CodingAleCR commented 3 years ago

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

CodingAleCR commented 3 years ago

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

jlubeck commented 3 years ago

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

CodingAleCR commented 3 years ago

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.

jlubeck commented 3 years ago

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

sergey-koba-mobidev commented 3 years ago

Hi, a patch version would be great indeed!

CodingAleCR commented 3 years ago

I will try to have by the weekend βœŒπŸΌπŸ™ŒπŸΌ

AhmedBenCheikh commented 3 years ago

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

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

CodingAleCR commented 3 years ago

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. 😊

AhmedBenCheikh commented 3 years ago

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

CodingAleCR commented 3 years ago

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.

AhmedBenCheikh commented 3 years ago

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