fix bug of empty error
MODIFY
lib/src/link/http/link_http.dart
lib/src/link/http/link_http.dart
@@ -281,13 +281,11 @@ HttpHeadersAndBody _selectHttpOptionsAndBody(
Future<FetchResult> _parseResponse(StreamedResponse response) async {
final int statusCode = response.statusCode;
- final String reasonPhrase = response.reasonPhrase;
- try {
final Encoding encoding = _determineEncodingFromResponse(response);
// @todo limit bodyBytes
- final Uint8List reponseByte = await response.stream.toBytes();
- final String decodedBody = encoding.decode(reponseByte);
+ final Uint8List responseByte = await response.stream.toBytes();
+ final String decodedBody = encoding.decode(responseByte);
final Map<String, dynamic> jsonResponse =
json.decode(decodedBody) as Map<String, dynamic>;
@@ -301,17 +299,16 @@ Future<FetchResult> _parseResponse(StreamedResponse response) async {
fetchResult.data = jsonResponse['data'];
}
- return fetchResult;
- } catch (e) {
- // @todo get body as well;
- // final String decodedBody = encoding.decode(response.bodyBytes);
+ if (fetchResult.data == null && fetchResult.errors == null) {
if (statusCode < 200 || statusCode >= 400) {
throw ClientException(
- 'Network Error: $statusCode $reasonPhrase',
+ 'Network Error: $statusCode $decodedBody',
);
}
- rethrow;
+ throw ClientException('Invalid response body: $decodedBody');
}
+
+ return fetchResult;
}
/// Returns the charset encoding for the given response.

MODIFY
pubspec.yaml
pubspec.yaml
@@ -4,6 +4,7 @@ version: 1.0.0-beta.1+1
authors:
- Eus Dima <eus@zinoapp.com>
- Zino Hofmann <zino@zinoapp.com>
+ - TruongSinh Tran-Nguyen <i@truongsinh.pro>
homepage: https://github.com/zino-app/graphql-flutter/tree/next
dependencies:

MODIFY
test/graphql_flutter_test.dart
test/graphql_flutter_test.dart
@@ -142,7 +142,12 @@ void main() {
});
// test('failed query because of network', {});
// test('failed query because of because of error response', {});
-// test('failed query because of because of invalid response', {});
+// test('failed query because of because of invalid response', () {
+// String responseBody =
+// '{\"message\":\"Bad credentials\",\"documentation_url\":\"https://developer.github.com/v4\"}';
+// int responseCode = 401;
+// });
+// test('partially success query with some errors', {});
});
group('mutation', () {
test('successful mutation', () async {
@@ -357,5 +362,11 @@ void main() {
},
]);
});
+
+// test('upload fail error response', () {
+// const String responseBody =
+// r'{"errors":[{"message":"Variable \"$files\" of required type \"[Upload!]!\" was not provided.","locations":[{"line":1,"column":14}],"extensions":{"code":"INTERNAL_SERVER_ERROR","exception":{"stacktrace":["GraphQLError: Variable \"$files\" of required type \"[Upload!]!\" was not provided."," at getVariableValues (/Users/truongsinh/Dev/flutter/graphql-flutter/example/server/api/node_modules/graphql/execution/values.js:76:21)"," at buildExecutionContext (/Users/truongsinh/Dev/flutter/graphql-flutter/example/server/api/node_modules/graphql/execution/execute.js:196:63)"," at executeImpl (/Users/truongsinh/Dev/flutter/graphql-flutter/example/server/api/node_modules/graphql/execution/execute.js:70:20)"," at Object.execute (/Users/truongsinh/Dev/flutter/graphql-flutter/example/server/api/node_modules/graphql/execution/execute.js:62:35)"," at /Users/truongsinh/Dev/flutter/graphql-flutter/example/server/api/node_modules/apollo-server-core/dist/requestPipeline.js:195:36"," at Generator.next (<anonymous>)"," at /Users/truongsinh/Dev/flutter/graphql-flutter/example/server/api/node_modules/apollo-server-core/dist/requestPipeline.js:7:71"," at new Promise (<anonymous>)"," at __awaiter (/Users/truongsinh/Dev/flutter/graphql-flutter/example/server/api/node_modules/apollo-server-core/dist/requestPipeline.js:3:12)"," at execute (/Users/truongsinh/Dev/flutter/graphql-flutter/example/server/api/node_modules/apollo-server-core/dist/requestPipeline.js:179:20)"," at Object.<anonymous> (/Users/truongsinh/Dev/flutter/graphql-flutter/example/server/api/node_modules/apollo-server-core/dist/requestPipeline.js:131:35)"," at Generator.next (<anonymous>)"," at fulfilled (/Users/truongsinh/Dev/flutter/graphql-flutter/example/server/api/node_modules/apollo-server-core/dist/requestPipeline.js:4:58)"," at process._tickCallback (internal/process/next_tick.js:68:7)"]}}}]';
+// const int statusCode = 400;
+// });
});
}

fix bug of empty error (#5)