mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 07:09:15 +01:00
rpc: Avoid returning HTTP errors for JSON-RPC 2.0 requests
Avoid returning HTTP status errors for non-batch JSON-RPC 2.0 requests if the RPC method failed but the HTTP request was otherwise valid. Batch requests already did not return HTTP errors previously.
This commit is contained in:
@@ -358,11 +358,20 @@ bool IsDeprecatedRPCEnabled(const std::string& method)
|
||||
return find(enabled_methods.begin(), enabled_methods.end(), method) != enabled_methods.end();
|
||||
}
|
||||
|
||||
UniValue JSONRPCExec(const JSONRPCRequest& jreq)
|
||||
UniValue JSONRPCExec(const JSONRPCRequest& jreq, bool catch_errors)
|
||||
{
|
||||
// Might throw exception. Single requests will throw and send HTTP error codes
|
||||
// but inside a batch, we just include the error object and return HTTP 200
|
||||
UniValue result = tableRPC.execute(jreq);
|
||||
UniValue result;
|
||||
if (catch_errors) {
|
||||
try {
|
||||
result = tableRPC.execute(jreq);
|
||||
} catch (UniValue& e) {
|
||||
return JSONRPCReplyObj(NullUniValue, std::move(e), jreq.id, jreq.m_json_version);
|
||||
} catch (const std::exception& e) {
|
||||
return JSONRPCReplyObj(NullUniValue, JSONRPCError(RPC_MISC_ERROR, e.what()), jreq.id, jreq.m_json_version);
|
||||
}
|
||||
} else {
|
||||
result = tableRPC.execute(jreq);
|
||||
}
|
||||
|
||||
return JSONRPCReplyObj(std::move(result), NullUniValue, jreq.id, jreq.m_json_version);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user