def api_failed(response, endpoint, exit_on_error=True):
    """
    Check if api request failed

    Can raise exception
    """

    if 200 <= response.status_code < 300:
        return False

    if exit_on_error:
        raise Exception("Status code {0} calling {1}".format(
            response.status_code, endpoint))
    return True