Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Future already completed #1480

Closed
jargalbat opened this issue May 19, 2022 · 34 comments
Closed

Future already completed #1480

jargalbat opened this issue May 19, 2022 · 34 comments

Comments

@jargalbat
Copy link

When calling requests, the error has been thrown randomly.

Error: Bad state: Future already completed
at Object.throw_ [as throw] (http://localhost:1234/dart_sdk.js:5067:11)
at _AsyncCompleter.new.completeError (http://localhost:1234/dart_sdk.js:35195:51)
at http://localhost:1234/packages/dio/src/interceptors/log.dart.lib.js:651:25
at _RootZone.runUnary (http://localhost:1234/dart_sdk.js:40441:59)
at _FutureListener.then.handleValue (http://localhost:1234/dart_sdk.js:35363:29)
at handleValueCallback (http://localhost:1234/dart_sdk.js:35931:49)
at Function._propagateToListeners (http://localhost:1234/dart_sdk.js:35969:17)
at _Future.new.[_complete] (http://localhost:1234/dart_sdk.js:35809:25)
at http://localhost:1234/dart_sdk.js:34915:30
at internalCallback (http://localhost:1234/dart_sdk.js:26619:11)

_dio.interceptors.add(CustomInterceptors());

// ...

class CustomInterceptors extends Interceptor {
  @override
  void onError(DioError err, ErrorInterceptorHandler handler) async {
    if (err.response != null) {
      if (err.response!.statusCode == 401) {
        // ...
        handler.resolve(response);
      } else {
        handler.next(err);
      }
    }

    return super.onError(err, handler);
  }
}

Issue Info

Info Value
Platform Name Chrome
Dio Version 4.0.6
Android Studio Version 2021.1.1 Patch 2

Issue Description and Steps

Tried using flutter config --no-analytics. It didn't work.

@alreadytaken1990
Copy link

change version to v4.0.4, same #1452 , wait for solute

@YouchanChung
Copy link

same issue..

@Dkrinker
Copy link

Dkrinker commented Jun 1, 2022

Same issue

@yairsts
Copy link

yairsts commented Jun 6, 2022

Same issue...

@ZhZhZhen
Copy link

我在web项目中,也会输出这个错误

@marcelomdea
Copy link

Same issue...

@mdeandrea-mrmilu
Copy link

Related to #1497 and PR #1496

@grinder15
Copy link

Same issue.

@loidy
Copy link

loidy commented Jul 29, 2022

Still happening in 4.0.6

@angelomedeiros
Copy link

Same issue.

@Amr-SymTerra
Copy link

Same issue

1 similar comment
@vrsct
Copy link

vrsct commented Sep 1, 2022

Same issue

@klepon
Copy link

klepon commented Sep 2, 2022

same issue

1 similar comment
@TryImpossible
Copy link

same issue

@hamzakhurshid12
Copy link

Same issue

3 similar comments
@kenNg1
Copy link

kenNg1 commented Sep 14, 2022

Same issue

@tranducthang1505
Copy link

Same issue

@nicolaspernoud
Copy link

Same issue

@SumanPoudel0699
Copy link

SumanPoudel0699 commented Sep 23, 2022

https://stackoverflow.com/a/73824643/19475845

I have written one solution in StackOverflow this helps me to get rid of Error: Bad state: Future already completed error may help you also

@ikallali
Copy link

+1

1 similar comment
@CrazyboyQCD
Copy link

+1

@Wbqqqq
Copy link

Wbqqqq commented Dec 22, 2022

+1

3 similar comments
@HasanAlqaisi
Copy link

+1

@ajikmat
Copy link

ajikmat commented Jan 18, 2023

+1

@metafounder
Copy link

+1

@adbelemvy
Copy link

same issue here

@botaditya
Copy link

Same issue being faced by me

@marjandn
Copy link

marjandn commented Feb 3, 2023

I have this issue as well

@mdeandrea-mrmilu
Copy link

@AlexV525 why this issue is closed? Someone fix this bug?

@AlexV525
Copy link
Member

Yes, in #1550.

@MajedDH
Copy link

MajedDH commented Feb 25, 2023

I had the same issue.

I really spent hours to figure out that the handler should be called once. my code was wrongly calling handler.resolve and then handler.next.

I corrected the code to call only one of them (if else) , it worked like a charm.

@phamquoctrongnta
Copy link

For anyone come late
I just removed super.onError(err, handler); on onError method.

@kuhnroyal
Copy link
Member

#2130 improves the error message for this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests