diff options
author | furszy <matiasfurszyfer@protonmail.com> | 2022-09-14 12:13:58 -0300 |
---|---|---|
committer | furszy <matiasfurszyfer@protonmail.com> | 2022-09-15 10:24:53 -0300 |
commit | 55566630c60d23993a52ed54c95e7891f4588d57 (patch) | |
tree | 5a8240923ad568e30388205f567798f88ab08095 /src/rpc | |
parent | f523df1ee8661e0c4738694b9054952769bfff65 (diff) |
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).
Diffstat (limited to 'src/rpc')
-rw-r--r-- | src/rpc/server.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index e9987d73be..46f5ecd748 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -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()); } } |