Regularize irregular results for websocket interface too.

This commit is contained in:
Arthur Britto
2012-12-02 18:25:12 -08:00
parent c6db85fb39
commit 14bf7d0ec2
2 changed files with 19 additions and 19 deletions

View File

@@ -2154,23 +2154,7 @@ Json::Value RPCHandler::doRpcCommand(const std::string& strCommand, Json::Value&
jvRequest["command"] = strCommand; jvRequest["command"] = strCommand;
Json::Value jvResult; Json::Value jvResult = doCommand(jvRequest, iRole);
Json::Value jvRaw = doCommand(jvRequest, iRole);
// Regularize result.
if (jvRaw.isObject())
{
// Got an object.
jvResult = jvRaw;
}
else
{
// Probably got a string.
jvResult = Json::Value(Json::objectValue);
jvResult["message"] = jvRaw;
}
// Always report "status". On an error report the request as received. // Always report "status". On an error report the request as received.
if (jvResult.isMember("error")) if (jvResult.isMember("error"))
@@ -2306,7 +2290,23 @@ cLog(lsDEBUG) << "params.size: " << jvParams.size() << " array: " << jvParams.is
else else
{ {
try { try {
return (this->*(commandsA[i].dfpFunc))(jvParams); Json::Value jvRaw = (this->*(commandsA[i].dfpFunc))(jvParams);
// Regularize result.
if (jvRaw.isObject())
{
// Got an object.
return jvRaw;
}
else
{
// Probably got a string.
Json::Value jvResult(Json::objectValue);
jvResult["message"] = jvRaw;
return jvResult;
}
} }
catch (std::exception& e) catch (std::exception& e)
{ {

View File

@@ -79,7 +79,7 @@ Json::Value WSConnection::invokeCommand(Json::Value& jvRequest)
// consistent. // consistent.
// //
// Regularize result. This is duplicate code. // Regularize result. This is duplicate code.
if (jvResult["result"].isObject() && jvResult["result"].isMember("error")) if (jvResult["result"].isMember("error"))
{ {
jvResult = jvResult["result"]; jvResult = jvResult["result"];
jvResult["status"] = "error"; jvResult["status"] = "error";