提交 e596f53a 编写于 作者: P Pavel Kartavyy

ZooKeeper: throw correct exception code in get method [#METR-16142]

上级 269b4b81
......@@ -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);
......
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册