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

Repeatedly send post request error #171

Closed
slb2709673 opened this issue Jun 26, 2018 · 5 comments
Closed

Repeatedly send post request error #171

slb2709673 opened this issue Jun 26, 2018 · 5 comments

Comments

@slb2709673
Copy link

[VERBOSE-2:dart_error.cc(16)] Unhandled exception:
type '(Exception) => Null' is not a subtype of type '(Object) => FutureOr'
#0 _FutureListener.handleError (dart:async/future_impl.dart:145:11)
#1 Future._propagateToListeners.handleError (dart:async/future_impl.dart:645:47)
#2 Future._propagateToListeners (dart:async/future_impl.dart:666:24)
#3 Future._completeError (dart:async/future_impl.dart:485:5)
#4 _SyncCompleter._completeError (dart:async/future_impl.dart:55:12)
#5 _Completer.completeError (dart:async/future_impl.dart:27:5)
#6 _withClient (package:http/http.dart)

#7 post (package:http/http.dart:70:3)
#8 _RightSlideState._loadRightCategroy (package:name/widget/categroy.dart:159:10)
#9 _RightSlideState.didUpdateWidget (package:name/widget/categroy.dart:148:5)
#10 StatefulElement.update (package:flutter/src/widgets/framework.dart:3784:58)
#11 Element.updateChild (package:flutter/src/widgets/framework.dart:<…>

@donny-dont
Copy link

@slb2709673 need a reproduction and more info like what version you're using.

@victoraugustolls
Copy link

victoraugustolls commented Jul 26, 2018

Using with flutter, package version ^0.11.3+16.

I'm having the same issue, code snippet below:

Future<Token> login(String username, String password) async {
    final body = {'email': username, 'password': password};
    final response = await http.post(
      this.baseUrl + '/auth',
      body: json.encode(body),
    );
    if (response.statusCode > 299) {
      print('Error ${response.statusCode}');
      throw("Response code: ${response?.statusCode}");
    } else {
      return Token.fromJson(json.decode(response.body)['data']);
    }
  }

And the stack trace:

[VERBOSE-2:dart_error.cc(16)] Unhandled exception:
type '(dynamic) => void' is not a subtype of type '(Object) => FutureOr<Token>'
#0      _FutureListener.handleError (dart:async/future_impl.dart:145:11)
#1      Future._propagateToListeners.handleError (dart:async/future_impl.dart:645:47)
#2      Future._propagateToListeners (dart:async/future_impl.dart:666:24)
#3      Future._completeError (dart:async/future_impl.dart:485:5)
#4      _SyncCompleter._completeError (dart:async/future_impl.dart:55:12)
#5      _Completer.completeError (dart:async/future_impl.dart:27:5)
#6      Network.login (package:barman/data/repository/api.dart)

@ghost
Copy link

ghost commented Aug 27, 2018

Since you're using Flutter this issue probably belongs over there.

However, I think what's common for both of you is that you're facing an 'Unhandled exception'.
@victoraugustolls' code above has two potential causes of this:

  • http.post(...) can potentially throw an exception, which isn't caught in the example code.
  • the example code itself also throws an exception.

Any uncaught exceptions will bubble up to whoever is calling the example code and will need to be handled there.
You can have a look at the guide on Futures and Error Handling.
But the TL;DR is you can try something like:

login(myUsername, myPassword)
    .then(processValue)
    .catchError(handleError);

@ghost ghost closed this as completed Aug 27, 2018
@victoraugustolls
Copy link

@cskau-g sorry, it was my first day with dart and flutter, and my code was totally off! I should have updated my situation here!

@ghost
Copy link

ghost commented Aug 28, 2018

No worries! I hope you were able to have fun and be productive with Dart and Flutter regardless. :)

This issue was closed.
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

3 participants