Report rpc port in error when unable to connect

This commit is contained in:
Duke Leto
2021-08-05 15:55:34 -04:00
parent 236d79b3f8
commit 89a4226965
4 changed files with 18 additions and 14 deletions

View File

@@ -28,9 +28,13 @@
#include <event2/buffer.h>
#include <event2/keyvalq_struct.h>
#include "support/events.h"
uint16_t ASSETCHAINS_RPCPORT = 18031;
uint16_t BITCOIND_RPCPORT = 18031;
char SMART_CHAIN_SYMBOL[65];
extern uint16_t ASSETCHAINS_RPCPORT;
#include <univalue.h>
using namespace std;
@@ -252,14 +256,16 @@ UniValue CallRPC(const std::string& strMethod, const UniValue& params)
event_base_dispatch(base.get());
if (response.status == 0)
throw CConnectionFailed(strprintf("couldn't connect to server: %s (code %d)\n(make sure server is running and you are connecting to the correct RPC port)", http_errorstring(response.error), response.error));
else if (response.status == HTTP_UNAUTHORIZED)
if (response.status == 0) {
throw CConnectionFailed(strprintf("couldn't connect to server at port %d : %s (code %d)\n(make sure server is running and you are connecting to the correct RPC port)",
ASSETCHAINS_RPCPORT, http_errorstring(response.error), response.error));
} else if (response.status == HTTP_UNAUTHORIZED) {
throw std::runtime_error("incorrect rpcuser or rpcpassword (authorization failed)");
else if (response.status >= 400 && response.status != HTTP_BAD_REQUEST && response.status != HTTP_NOT_FOUND && response.status != HTTP_INTERNAL_SERVER_ERROR)
} else if (response.status >= 400 && response.status != HTTP_BAD_REQUEST && response.status != HTTP_NOT_FOUND && response.status != HTTP_INTERNAL_SERVER_ERROR) {
throw std::runtime_error(strprintf("server returned HTTP error %d", response.status));
else if (response.body.empty())
throw std::runtime_error("no response from server");
} else if (response.body.empty()) {
throw std::runtime_error(strprintf("no response from server at port %d", ASSETCHAINS_RPCPORT ));
}
// Parse reply
UniValue valReply(UniValue::VSTR);