jonsaw / amazon-cognito-identity-dart

Unofficial Amazon Cognito Identity Provider Dart SDK, to easily add user sign-up and sign-in to your mobile and web apps with AWS.
MIT License
205 stars 93 forks source link

Exception when response body is empty #10

Closed mikes222 closed 6 years ago

mikes222 commented 6 years ago

Simple testprogram (even without changing the user pool id):

import 'package:amazon_cognito_identity_dart/cognito.dart';
import 'package:flutter_test/flutter_test.dart';

final userPool = new CognitoUserPool(
    'ap-southeast-1_xxxxxxxxx', 'xxxxxxxxxxxxxxxxxxxxxxxxxx');
final userAttributes = [
  new AttributeArg(name: 'first_name', value: 'Jimmy'),
  new AttributeArg(name: 'last_name', value: 'Wong'),
];

void main() {
  testWidgets('Amazon Cognito signup-test', (WidgetTester tester) async {
    var data = await userPool.signUp('email@inspire.my', 'Password001',
        userAttributes: userAttributes);
  });
}

The system responds with the followin stacktrace:

Unexpected end of input (at character 1)

^

When the exception was thrown, this was the stack:

0 _ChunkedJsonParser.fail (dart:convert/runtime/libconvert_patch.dart:1362:5)

1 _ChunkedJsonParser.close (dart:convert/runtime/libconvert_patch.dart:506:7)

2 _parseJson (dart:convert/runtime/libconvert_patch.dart:30:10)

3 JsonDecoder.convert (dart:convert/json.dart:542:36)

4 JsonCodec.decode (dart:convert/json.dart:169:41)

5 Client.request (package:amazon_cognito_identity_dart/src/client.dart:50:23)

#6 CognitoUserPool.signUp (package:amazon_cognito_identity_dart/src/cognito_user_pool.dart:95:34) #7 main. (file:///E:/develop/flutter_testapp/flutter_testapp/test/cognito_test.dart:14:31) #8 testWidgets... (package:flutter_test/src/widget_tester.dart:63:25) ... Though the solution is obvious I think a better/tailored exception is preferred since such error may also occur in production if the systems are for example overloaded.
jonsaw commented 6 years ago

For some strange reason, WidgetTester is returning a blank JSON body. Running the example app in Flutter or with Dart's test suite we gives us the following:

{__type: ResourceNotFoundException, message: User pool client xxxxxxxxxxxxxxxxxxxxxxxxxx does not exist.}

Anyway, better client request error handling is fixed in v0.0.16. Thanks for the suggestion.