mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Better error messages for out of range integral values
* This change passes detailed error messages from the JSON parser on the server side, back to the client for inclusion into the reply's error message. * Errors originating from the server's inability to parse are reclassified from rpcINTERNAL to rpcINVALID_PARAMS.
This commit is contained in:
@@ -1197,6 +1197,15 @@ std::string JSONRPCRequest (std::string const& strMethod, Json::Value const& par
|
||||
return to_string (request) + "\n";
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
// Special local exception type thrown when request can't be parsed.
|
||||
class RequestNotParseable : public std::runtime_error
|
||||
{
|
||||
using std::runtime_error::runtime_error; // Inherit constructors
|
||||
};
|
||||
};
|
||||
|
||||
struct RPCCallImp
|
||||
{
|
||||
// VFALCO NOTE Is this a to-do comment or a doc comment?
|
||||
@@ -1228,7 +1237,8 @@ struct RPCCallImp
|
||||
|
||||
// Parse reply
|
||||
JLOG (j.debug()) << "RPC reply: " << strData << std::endl;
|
||||
|
||||
if (strData.find("Unable to parse request") == 0)
|
||||
Throw<RequestNotParseable> (strData);
|
||||
Json::Reader reader;
|
||||
Json::Value jvReply;
|
||||
if (!reader.parse (strData, jvReply))
|
||||
@@ -1440,6 +1450,12 @@ rpcClient(std::vector<std::string> const& args,
|
||||
// YYY We could have a command line flag for single line output for scripts.
|
||||
// YYY We would intercept output here and simplify it.
|
||||
}
|
||||
catch (RequestNotParseable& e)
|
||||
{
|
||||
jvOutput = rpcError(rpcINVALID_PARAMS);
|
||||
jvOutput["error_what"] = e.what();
|
||||
nRet = rpcINVALID_PARAMS;
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
jvOutput = rpcError (rpcINTERNAL);
|
||||
|
||||
@@ -569,7 +569,8 @@ ServerHandlerImp::processRequest (Port const& port,
|
||||
! jsonOrig ||
|
||||
! (jsonOrig.isObject () || jsonOrig.isArray()))
|
||||
{
|
||||
HTTPReply (400, "Unable to parse request", output, rpcJ);
|
||||
HTTPReply (400, "Unable to parse request: " +
|
||||
reader.getFormatedErrorMessages(), output, rpcJ);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user