rpc: treat univalue type check error as RPC_TYPE_ERROR, not RPC_MISC_ERROR

By throwing a custom exception from `Univalue::checkType` (instead of a plain
std::runtime_error) and catching it on the RPC server request handler.

So we properly return RPC_TYPE_ERROR (-3) on arg type errors and
not the general RPC_MISC_ERROR (-1).
This commit is contained in:
furszy
2022-09-14 12:13:58 -03:00
parent f523df1ee8
commit 55566630c6
11 changed files with 28 additions and 24 deletions

View File

@@ -468,8 +468,7 @@ UniValue CRPCTable::execute(const JSONRPCRequest &request) const
static bool ExecuteCommand(const CRPCCommand& command, const JSONRPCRequest& request, UniValue& result, bool last_handler)
{
try
{
try {
RPCCommandExecution execution(request.strMethod);
// Execute, convert arguments to array if necessary
if (request.params.isObject()) {
@@ -477,9 +476,9 @@ static bool ExecuteCommand(const CRPCCommand& command, const JSONRPCRequest& req
} else {
return command.actor(request, result, last_handler);
}
}
catch (const std::exception& e)
{
} catch (const UniValue::type_error& e) {
throw JSONRPCError(RPC_TYPE_ERROR, e.what());
} catch (const std::exception& e) {
throw JSONRPCError(RPC_MISC_ERROR, e.what());
}
}