Skip to content

Commit a8eadb1

Browse files
committed
client: throw non-structured response errors as internal errors
Some servers return errors in a non-v1.1+ compliant manner, as text. An example in the wild is electrs (https://github.com/romanz/electrs). This behaviour was apparently common in pre-v1.1 servers, and since it is easy to support, throw the error with its text so the caller at least gets some error context rather than "invalid server response".
1 parent ec5b468 commit a8eadb1

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

include/jsonrpccxx/client.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ namespace jsonrpccxx {
5959
json response = json::parse(connector.Send(j.dump()));
6060
if (has_key_type(response, "error", json::value_t::object)) {
6161
throw JsonRpcException::fromJson(response["error"]);
62+
} else if (has_key_type(response, "error", json::value_t::string)) {
63+
throw JsonRpcException(-32603, response["error"]);
6264
}
6365
if (has_key(response, "result") && has_key(response, "id")) {
6466
if (response["id"].type() == json::value_t::string)

0 commit comments

Comments
 (0)