Skip to content

Commit b7122b3

Browse files
ittusJon Wayne Parrott
authored andcommitted
handle errors when received an array from api (#289)
1 parent c952fd0 commit b7122b3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

googleapiclient/errors.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ def _get_reason(self):
5252
reason = self.resp.reason
5353
try:
5454
data = json.loads(self.content.decode('utf-8'))
55-
reason = data['error']['message']
56-
except (ValueError, KeyError):
55+
if isinstance(data, dict):
56+
reason = data['error']['message']
57+
elif isinstance(data, list) and len(data) > 0:
58+
first_error = data[0]
59+
reason = first_error['error']['message']
60+
except (ValueError, KeyError, TypeError):
5761
pass
5862
if reason is None:
5963
reason = ''

0 commit comments

Comments
 (0)