def parse_response()

in src/basket/base.py [0:0]


def parse_response(res):
    """Parse the result of a basket API call, raise exception on error"""

    # Parse the json and check for errors
    # We assume all basket calls respond with JSON (they're supposed to)
    result = {}
    try:
        result = json.loads(res.content)
    except Exception:
        log.exception(f"Error parsing JSON returned by basket ({res.content})")

    if res.status_code != 200 or result.get("status", "") == "error":
        desc = result.get("desc", f"{res.status_code} request returned from basket: {res.content}")
        raise BasketException(desc, status_code=res.status_code, code=result.get("code", errors.BASKET_UNKNOWN_ERROR), result=result)

    return result