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/univalue | |
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/univalue')
-rw-r--r-- | src/univalue/include/univalue.h | 5 | ||||
-rw-r--r-- | src/univalue/lib/univalue.cpp | 2 |
2 files changed, 6 insertions, 1 deletions
diff --git a/src/univalue/include/univalue.h b/src/univalue/include/univalue.h index ccaf56a271..850d0a1cbc 100644 --- a/src/univalue/include/univalue.h +++ b/src/univalue/include/univalue.h @@ -19,6 +19,11 @@ class UniValue { public: enum VType { VNULL, VOBJ, VARR, VSTR, VNUM, VBOOL, }; + class type_error : public std::runtime_error + { + using std::runtime_error::runtime_error; + }; + UniValue() { typ = VNULL; } UniValue(UniValue::VType initialType, const std::string& initialStr = "") { typ = initialType; diff --git a/src/univalue/lib/univalue.cpp b/src/univalue/lib/univalue.cpp index 12a434dd0e..4448981d3e 100644 --- a/src/univalue/lib/univalue.cpp +++ b/src/univalue/lib/univalue.cpp @@ -210,7 +210,7 @@ const UniValue& UniValue::operator[](size_t index) const void UniValue::checkType(const VType& expected) const { if (typ != expected) { - throw std::runtime_error{"JSON value of type " + std::string{uvTypeName(typ)} + " is not of expected type " + + throw type_error{"JSON value of type " + std::string{uvTypeName(typ)} + " is not of expected type " + std::string{uvTypeName(expected)}}; } } |