'Check for RPC success and translate exceptions.
This wraps rpc.check_success() and should be called instead of that.
This also removes the RPC from the list of pending RPCs, once it
has completed.
Args:
rpc: A UserRPC or MultiRpc object.
Raises:
Nothing if the call succeeded; various datastore_errors.Error
subclasses if ApplicationError was raised by rpc.check_success().'

def check_rpc_success(self, rpc):

    try:
        rpc.wait()
    finally:
        self._remove_pending(rpc)
    try:
        rpc.check_success()
    except apiproxy_errors.ApplicationError as err:
        raise _ToDatastoreError(err)
