Skip to content

Commit

Permalink
Clean up health check API response (#2779)
Browse files Browse the repository at this point in the history
* Clean up logs formatting

* Better response
  • Loading branch information
sieniven authored Jan 13, 2024
1 parent 76eb7e7 commit a3b18d7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ static bool rest_blockchain_readiness(HTTPRequest* req, const std::string&) {

if (status["health_status"].get_bool()) {
req->WriteHeader("Content-Type", "text/plain");
req->WriteReply(HTTP_OK, "Health status: Ready - sync-to-tip: true, active-peers: true.");
req->WriteReply(HTTP_OK, "Health status: Ready - sync-to-tip: true, active-peers: true.\n");
return true;
} else {
std::string syncToTip = "false";
Expand All @@ -656,17 +656,17 @@ static bool rest_blockchain_readiness(HTTPRequest* req, const std::string&) {
if (status["active_peer_nodes"].get_bool()) {
activePeerNodes = "true";
}
RESTERR(req, HTTP_SERVICE_UNAVAILABLE, strprintf("Health status: Not ready - sync-to-tip: %s, active-peers: %s.", syncToTip, activePeerNodes));
RESTERR(req, HTTP_SERVICE_UNAVAILABLE, strprintf("Health status: Not ready - sync-to-tip: %s, active-peers: %s.\n", syncToTip, activePeerNodes));
return false;
}
} catch (const UniValue& objError) {
HTTPStatusCode nStatus = HTTP_INTERNAL_SERVER_ERROR;
std::string msg = "";
int code = find_value(objError, "code").get_int();

if (code == RPC_CLIENT_P2P_DISABLED)
if (code == RPC_CLIENT_P2P_DISABLED) {
nStatus = HTTP_SERVICE_UNAVAILABLE;
msg = "Error: Peer-to-peer functionality missing or disabled";
msg = "Health status: Not ready - peer-to-peer functionality missing or disabled.\n";
}
RESTERR(req, nStatus, msg);
return false;
} catch (const std::exception& e) {
Expand Down

0 comments on commit a3b18d7

Please sign in to comment.