Query a resource until a successful response, and decode the return data

    CLI Example:

    .. code-block:: bash

        salt '*' http.wait_for_successful_query http://somelink.com/ wait_for=160

def wait_for_successful_query(url, wait_for=300, **kwargs):
    '''
    Query a resource until a successful response, and decode the return data

    CLI Example:

    .. code-block:: bash

        salt '*' http.wait_for_successful_query http://somelink.com/ wait_for=160
    '''

    starttime = time.time()

    while True:
        caught_exception = None
        result = None
        try:
            result = query(url=url, **kwargs)
            if not result.get('Error') and not result.get('error'):
                return result
        except Exception as exc:
            caught_exception = exc

        if time.time() > starttime + wait_for:
            if not result and caught_exception:
                # workaround pylint bug https://www.logilab.org/ticket/3207
                raise caught_exception  # pylint: disable=E0702

            return result