diff --git a/src/rest.cpp b/src/rest.cpp index 586b543791e0..ac06fd635ff3 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -665,8 +665,16 @@ static bool rest_deploymentinfo(const CoreContext& context, HTTPRequest* req, co jsonRequest.params.push_back(hash_str); } + std::string result; + try { + result = getdeploymentinfo().HandleRequest(jsonRequest).write() + "\n"; + } catch (const UniValue& error) { + return RESTERR(req, HTTP_INTERNAL_SERVER_ERROR, error["message"].get_str()); + } catch (const std::exception& error) { + return RESTERR(req, HTTP_INTERNAL_SERVER_ERROR, error.what()); + } req->WriteHeader("Content-Type", "application/json"); - req->WriteReply(HTTP_OK, getdeploymentinfo().HandleRequest(jsonRequest).write() + "\n"); + req->WriteReply(HTTP_OK, result); return true; } default: { diff --git a/test/functional/interface_rest.py b/test/functional/interface_rest.py index bb48d245cd8a..7436f36fa1b9 100755 --- a/test/functional/interface_rest.py +++ b/test/functional/interface_rest.py @@ -435,5 +435,20 @@ def run_test(self): resp = self.test_rest_request(f"/deploymentinfo/{INVALID_PARAM}", ret_type=RetType.OBJ, status=400) assert_equal(resp.read().decode('utf-8').rstrip(), f"Invalid hash: {INVALID_PARAM}") + self.log.info("Test deployment info with unavailable block data") + self.generate(self.nodes[0], max(0, 432 - self.nodes[0].getblockcount())) + tip_before_request = self.nodes[0].getbestblockhash() + self.disconnect_nodes(0, 1) + header_only_hash = self.generate(self.nodes[1], 1, sync_fun=self.no_op)[0] + self.nodes[0].submitheader(self.nodes[1].getblockheader(header_only_hash, False)) + resp = self.test_rest_request(f"/deploymentinfo/{header_only_hash}", ret_type=RetType.OBJ, status=500) + assert_equal(resp.getheader('Content-Type'), 'text/plain') + assert_equal(resp.read().decode('utf-8').rstrip(), "failed-getehfforblock-read") + assert_equal(self.nodes[0].getbestblockhash(), tip_before_request) + assert_equal(self.test_rest_request('/deploymentinfo'), self.nodes[0].getdeploymentinfo()) + self.connect_nodes(0, 1) + self.sync_all() + assert_equal(self.test_rest_request(f"/deploymentinfo/{header_only_hash}"), self.nodes[0].getdeploymentinfo(header_only_hash)) + if __name__ == '__main__': RESTTest().main()