def handle_rpc_errors(fnc):
    'Decorator to add more context to RPC errors'

    @wraps(fnc)
    def wrapper(*args, **kwargs):
        try:
            return fnc(*args, **kwargs)
        except grpc.RpcError as exc:
            exc.code().value
            exc.details()
            if (exc.code() == grpc.StatusCode.UNIMPLEMENTED):
                print('unimplemented')
                raise exc
            elif (exc.code() == grpc.StatusCode.UNAVAILABLE):
                print('UNAVAILABLE')
                print(f'ERROR MESSAGE: {exc.details()}')
            elif ((exc.code() == grpc.StatusCode.UNKNOWN) and (exc.details() == 'wallet locked, unlock it to enable full RPC access')):
                print('WALLET IS LOCKED!')
                raise exc
            elif (exc.code() == grpc.StatusCode.UNKNOWN):
                print('unknown')
                print(f'ERROR MESSAGE: {exc.details()}')
            elif (exc.code() == grpc.StatusCode.NOT_FOUND):
                print('NOT FOUND')
                print(f'ERROR MESSAGE: {exc.details()}')
            elif (exc.code() == grpc.StatusCode.PERMISSION_DENIED):
                print('PERMISSION_DENIED')
                print(f'ERROR MESSAGE: {exc.details()}')
            else:
                raise exc
                return exc
        except Exception as exc:
            print('unknown exception')
            print(exc)
    return wrapper
Decorator to add more context to RPC errors
def handle_rpc_errors(fnc):
    

    @wraps(fnc)
    def wrapper(*args, **kwargs):
        try:
            return fnc(*args, **kwargs)
        except grpc.RpcError as exc:
            exc.code().value
            exc.details()
            if (exc.code() == grpc.StatusCode.UNIMPLEMENTED):
                print('unimplemented')
                raise exc
            elif (exc.code() == grpc.StatusCode.UNAVAILABLE):
                print('UNAVAILABLE')
                print(f'ERROR MESSAGE: {exc.details()}')
            elif ((exc.code() == grpc.StatusCode.UNKNOWN) and (exc.details() == 'wallet locked, unlock it to enable full RPC access')):
                print('WALLET IS LOCKED!')
                raise exc
            elif (exc.code() == grpc.StatusCode.UNKNOWN):
                print('unknown')
                print(f'ERROR MESSAGE: {exc.details()}')
            elif (exc.code() == grpc.StatusCode.NOT_FOUND):
                print('NOT FOUND')
                print(f'ERROR MESSAGE: {exc.details()}')
            elif (exc.code() == grpc.StatusCode.PERMISSION_DENIED):
                print('PERMISSION_DENIED')
                print(f'ERROR MESSAGE: {exc.details()}')
            else:
                raise exc
                return exc
        except Exception as exc:
            print('unknown exception')
            print(exc)
    return wrapper