diff --git a/libs/libzkutil/include/zkutil/ZooKeeper.h b/libs/libzkutil/include/zkutil/ZooKeeper.h index e2727265ca270355c1d9a7d18814640fe8b7f3c9..03c4df7a155b3e6596efa60b907114788068bf54 100644 --- a/libs/libzkutil/include/zkutil/ZooKeeper.h +++ b/libs/libzkutil/include/zkutil/ZooKeeper.h @@ -120,7 +120,7 @@ public: /** Не бросает исключение при следующих ошибках: * - Такой ноды нет. В таком случае возвращает false. */ - bool tryGet(const std::string & path, std::string & res, Stat * stat = nullptr, EventPtr watch = nullptr); + bool tryGet(const std::string & path, std::string & res, Stat * stat = nullptr, EventPtr watch = nullptr, int * code = nullptr); void set(const std::string & path, const std::string & data, int32_t version = -1, Stat * stat = nullptr); diff --git a/libs/libzkutil/src/ZooKeeper.cpp b/libs/libzkutil/src/ZooKeeper.cpp index 26ea0aae8966fb0ac56be20bb265ae671896edff..6ca04aae05fd0e1469ec51926285b25502a71157 100644 --- a/libs/libzkutil/src/ZooKeeper.cpp +++ b/libs/libzkutil/src/ZooKeeper.cpp @@ -372,14 +372,15 @@ int32_t ZooKeeper::getImpl(const std::string & path, std::string & res, Stat * s std::string ZooKeeper::get(const std::string & path, Stat * stat, EventPtr watch) { + int code; std::string res; - if (tryGet(path, res, stat, watch)) + if (tryGet(path, res, stat, watch, &code)) return res; else - throw KeeperException("Can't get data for node " + path + ": node doesn't exist"); + throw KeeperException("Can't get data for node " + path + ": node doesn't exist", code); } -bool ZooKeeper::tryGet(const std::string & path, std::string & res, Stat * stat_, EventPtr watch) +bool ZooKeeper::tryGet(const std::string & path, std::string & res, Stat * stat_, EventPtr watch, int * return_code) { int32_t code = retry(std::bind(&ZooKeeper::getImpl, this, std::ref(path), std::ref(res), stat_, watch)); @@ -387,6 +388,9 @@ bool ZooKeeper::tryGet(const std::string & path, std::string & res, Stat * stat_ code == ZNONODE)) throw KeeperException(code, path); + if (return_code) + *return_code = code; + return code == ZOK; }