Skip to content

Commit

Permalink
Merge pull request zino-hofmann#359 from truongsinh/fix/error-handling
Browse files Browse the repository at this point in the history
fix(client): error handling

@truongsinh does this also need to be PRed against `beta` as well?
  • Loading branch information
micimize authored Aug 4, 2019
2 parents 16fb1d5 + 5c0f2e5 commit 8de7322
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/graphql/lib/src/core/query_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ class QueryManager {
// so try/catch to avoid "could not access message"
try {
errorMessage = error.message as String;
assert(errorMessage != null);
assert(errorMessage.isNotEmpty);
} catch (e) {
throw error;
}
Expand Down
27 changes: 26 additions & 1 deletion packages/graphql/test/graphql_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,32 @@ void main() {
expect(nodes[2]['viewerHasStarred'], false);
return;
});
// test('failed query because of network', {});

test('failed query because of an exception with null string', () async {
final e = Exception();
when(mockHttpClient.send(any)).thenAnswer((_) async {
throw e;
});

final Future<QueryResult> r = graphQLClientClient
.query(WatchQueryOptions(document: readRepositories));

await expectLater(r, throwsA(e));
return;
});

test('failed query because of an exception with empty string', () async {
final e = Exception('');
when(mockHttpClient.send(any)).thenAnswer((_) async {
throw e;
});

final Future<QueryResult> r = graphQLClientClient
.query(WatchQueryOptions(document: readRepositories));

await expectLater(r, throwsA(e));
return;
});
// test('failed query because of because of error response', {});
// test('failed query because of because of invalid response', () {
// String responseBody =
Expand Down

0 comments on commit 8de7322

Please sign in to comment.