コード例 #1
0
def check_status_code(response, codes=None):
    """Check HTTP status code and raise exception if incorrect.

    :param Response response: HTTP response
    :param codes: List of accepted codes or callable
    :raises: ApiError if code invalid
    """
    codes = codes or [httplib.OK]
    checker = (codes
               if callable(codes) else lambda resp: resp.status_code in codes)
    if not checker(response):
        raise exceptions.ApiError(response, response.json())
コード例 #2
0
def result_or_error(response):
    """Get `result` field from Betfair response or raise exception if not
    found.

    :param Response response:
    :raises: ApiError if no results passed
    """
    data = response.json()
    result = data.get('result')
    if result is not None:
        return result
    raise exceptions.ApiError(response, data)