discoveryapis_commons: improve error handling, release v1.0.2 (#301)
diff --git a/discoveryapis_commons/CHANGELOG.md b/discoveryapis_commons/CHANGELOG.md
index beb6c1c..0d69dc4 100644
--- a/discoveryapis_commons/CHANGELOG.md
+++ b/discoveryapis_commons/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 1.0.2
+
+- Handle the case where the content of error JSON is a `List` of `Map`
+ instances.
+
## 1.0.1
- Support Unicode file names in `MultipartMediaUploader`.
diff --git a/discoveryapis_commons/lib/src/api_requester.dart b/discoveryapis_commons/lib/src/api_requester.dart
index 4951c2f..6a01f1d 100644
--- a/discoveryapis_commons/lib/src/api_requester.dart
+++ b/discoveryapis_commons/lib/src/api_requester.dart
@@ -11,7 +11,6 @@
import 'request_impl.dart';
import 'requests.dart' as client_requests;
import 'resumable_media_uploader.dart';
-
import 'utils.dart';
/// Base class for all API clients, offering generic methods for
@@ -276,7 +275,11 @@
// Some error happened, try to decode the response and fetch the error.
final stringStream = _decodeStreamAsText(response);
if (stringStream != null) {
- final jsonResponse = await stringStream.transform(json.decoder).first;
+ var jsonResponse = await stringStream.transform(json.decoder).first;
+ if (jsonResponse is List && jsonResponse.length == 1) {
+ jsonResponse = jsonResponse.first;
+ }
+
if (jsonResponse is Map && jsonResponse['error'] is Map) {
final error = jsonResponse['error'] as Map;
final codeValue = error['code'];
diff --git a/discoveryapis_commons/pubspec.yaml b/discoveryapis_commons/pubspec.yaml
index 4b1efe5..c775c59 100644
--- a/discoveryapis_commons/pubspec.yaml
+++ b/discoveryapis_commons/pubspec.yaml
@@ -1,5 +1,5 @@
name: _discoveryapis_commons
-version: 1.0.1
+version: 1.0.2
description: Library for use by client APIs generated from Discovery Documents.
repository: https://github.com/dart-lang/googleapis
environment: