def parse_reason(response, content):
    """
    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
    """
    def first_error(data):
        errors = data['error']['errors']
        if len(errors) > 1:
            # we have more than one error. We should capture that?
            logging.info('Received {} errors'.format(len(errors)))
        return errors[0]

    try:
        json_data = json.loads(content)
        return first_error(json_data)['reason']
    except:
        return response.reason
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