예제 #1
0
파일: helper.py 프로젝트: r0qs/indy-plenum
def sdk_check_reply(req_res):
    req, res = req_res
    if isinstance(res, ErrorCode):
        if res == ErrorCode.PoolLedgerTimeout:
            raise PoolLedgerTimeoutException(
                'Got PoolLedgerTimeout for request {}'.format(req))
        else:
            raise CommonSdkIOException(
                'Got an error with code {} for request {}'.format(res, req))
    if not isinstance(res, dict):
        raise CommonSdkIOException("Unexpected response format {}".format(res))

    def _parse_op(res_dict):
        if res_dict['op'] == REQNACK:
            raise RequestNackedException('ReqNack of id {}. Reason: {}'.format(
                req['reqId'], res_dict['reason']))
        if res_dict['op'] == REJECT:
            raise RequestRejectedException(
                'Reject of id {}. Reason: {}'.format(req['reqId'],
                                                     res_dict['reason']))

    if 'op' in res:
        _parse_op(res)
    else:
        for resps in res.values():
            if isinstance(resps, str):
                _parse_op(json.loads(resps))
            elif isinstance(resps, dict):
                _parse_op(resps)
            else:
                raise CommonSdkIOException(
                    "Unexpected response format {}".format(res))
예제 #2
0
def sdk_check_reply(req_res):
    req, res = req_res
    if isinstance(res, ErrorCode):
        if res == ErrorCode.PoolLedgerTimeout:
            raise PoolLedgerTimeoutException(
                'Got PoolLedgerTimeout for request {}'.format(req))
        else:
            raise CommonSdkIOException(
                'Got an error with code {} for request {}'.format(res, req))
    if res['op'] == REQNACK:
        raise RequestNackedException('ReqNack of id {}. Reason: {}'.format(
            req['reqId'], res['reason']))
    if res['op'] == REJECT:
        raise RequestRejectedException('Reject of id {}. Reason: {}'.format(
            req['reqId'], res['reason']))