def parse_reason(response, content):
def first_error(data):<EOL><INDENT>errors = data['<STR_LIT:error>']['<STR_LIT>']<EOL>if len(errors) > <NUM_LIT:1>:<EOL><INDENT>logging.info('<STR_LIT>'.format(len(errors)))<EOL><DEDENT>return errors[<NUM_LIT:0>]<EOL><DEDENT>try:<EOL><INDENT>json_data = json.loads(content)<EOL>return first_error(json_data)['<STR_LIT>']<EOL><DEDENT>except:<EOL><INDENT>return response.reason<EOL><DEDENT>
Google return a JSON document describing the error. We should parse this
and extract the error reason. See
https://developers.google.com/analytics/devguides/reporting/core/v3/coreErrors