def _raise_for(r, type, path):
    """
    Check response and raise if any errors - else retrieve relevant type of result (json or text)
    :param Response r:
    :param str type:
    :param str path:
    :rtype: dict|str
    """
    if r.status_code != 200:
        raise Exception('Unable to {} {}: {}'.format(type, path, r.text))
    if r.headers['Content-Type'].find('json') > 0:
        return r.json()
    else:
        return r.text
