diff --git a/plugins/chain_plugin/chain_plugin.cpp b/plugins/chain_plugin/chain_plugin.cpp index 86d877b413..26716786f2 100644 --- a/plugins/chain_plugin/chain_plugin.cpp +++ b/plugins/chain_plugin/chain_plugin.cpp @@ -2295,6 +2295,7 @@ void read_write::send_transaction2(const read_write::send_transaction2_params& p } read_only::get_abi_results read_only::get_abi( const get_abi_params& params, const fc::time_point& deadline )const { + try { get_abi_results result; result.account_name = params.account_name; const auto& d = db.db(); @@ -2305,9 +2306,11 @@ read_only::get_abi_results read_only::get_abi( const get_abi_params& params, con } return result; + } EOS_RETHROW_EXCEPTIONS(chain::account_query_exception, "unable to retrieve account abi") } read_only::get_code_results read_only::get_code( const get_code_params& params, const fc::time_point& deadline )const { + try { get_code_results result; result.account_name = params.account_name; const auto& d = db.db(); @@ -2327,9 +2330,11 @@ read_only::get_code_results read_only::get_code( const get_code_params& params, } return result; + } EOS_RETHROW_EXCEPTIONS(chain::account_query_exception, "unable to retrieve account code") } read_only::get_code_hash_results read_only::get_code_hash( const get_code_hash_params& params, const fc::time_point& deadline )const { + try { get_code_hash_results result; result.account_name = params.account_name; const auto& d = db.db(); @@ -2339,9 +2344,11 @@ read_only::get_code_hash_results read_only::get_code_hash( const get_code_hash_p result.code_hash = accnt.code_hash; return result; + } EOS_RETHROW_EXCEPTIONS(chain::account_query_exception, "unable to retrieve account code hash") } read_only::get_raw_code_and_abi_results read_only::get_raw_code_and_abi( const get_raw_code_and_abi_params& params, const fc::time_point& deadline)const { + try { get_raw_code_and_abi_results result; result.account_name = params.account_name; @@ -2355,9 +2362,11 @@ read_only::get_raw_code_and_abi_results read_only::get_raw_code_and_abi( const g result.abi = blob{{accnt_obj.abi.begin(), accnt_obj.abi.end()}}; return result; + } EOS_RETHROW_EXCEPTIONS(chain::account_query_exception, "unable to retrieve account code/abi") } read_only::get_raw_abi_results read_only::get_raw_abi( const get_raw_abi_params& params, const fc::time_point& deadline )const { + try { get_raw_abi_results result; result.account_name = params.account_name; @@ -2371,9 +2380,11 @@ read_only::get_raw_abi_results read_only::get_raw_abi( const get_raw_abi_params& result.abi = blob{{accnt_obj.abi.begin(), accnt_obj.abi.end()}}; return result; + } EOS_RETHROW_EXCEPTIONS(chain::account_query_exception, "unable to retrieve account abi") } read_only::get_account_results read_only::get_account( const get_account_params& params, const fc::time_point& deadline )const { + try { get_account_results result; result.account_name = params.account_name; @@ -2541,6 +2552,7 @@ read_only::get_account_results read_only::get_account( const get_account_params& } } return result; + } EOS_RETHROW_EXCEPTIONS(chain::account_query_exception, "unable to retrieve account info") } read_only::get_required_keys_result read_only::get_required_keys( const get_required_keys_params& params, const fc::time_point& deadline )const { diff --git a/plugins/http_plugin/http_plugin.cpp b/plugins/http_plugin/http_plugin.cpp index 607187c0e7..d72ef4c763 100644 --- a/plugins/http_plugin/http_plugin.cpp +++ b/plugins/http_plugin/http_plugin.cpp @@ -391,6 +391,9 @@ namespace eosio { } catch (chain::invalid_http_request& e) { error_results results{400, "Invalid Request", error_results::error_info(e, verbose_http_errors)}; cb( 400, fc::time_point::maximum(), fc::variant( results )); + } catch (chain::account_query_exception& e) { + error_results results{400, "Account lookup", error_results::error_info(e, verbose_http_errors)}; + cb( 400, fc::time_point::maximum(), fc::variant( results )); } catch (chain::unsatisfied_authorization& e) { error_results results{401, "UnAuthorized", error_results::error_info(e, verbose_http_errors)}; cb( 401, fc::time_point::maximum(), fc::variant( results )); diff --git a/tests/plugin_http_api_test.py b/tests/plugin_http_api_test.py index e59109cc9c..9573767ae0 100755 --- a/tests/plugin_http_api_test.py +++ b/tests/plugin_http_api_test.py @@ -337,7 +337,7 @@ def test_ChainApi(self) : # get_account with valid parameter payload = {"account_name":"default"} ret_json = self.nodeos.processUrllibRequest(resource, command, payload) - self.assertEqual(ret_json["code"], 500) + self.assertEqual(ret_json["code"], 400) # get_code with empty parameter command = "get_code" @@ -355,7 +355,7 @@ def test_ChainApi(self) : # get_code with valid parameter payload = {"account_name":"default"} ret_json = self.nodeos.processUrllibRequest(resource, command, payload) - self.assertEqual(ret_json["code"], 500) + self.assertEqual(ret_json["code"], 400) # get_code_hash with empty parameter command = "get_code_hash" @@ -373,7 +373,7 @@ def test_ChainApi(self) : # get_code_hash with valid parameter payload = {"account_name":"default"} ret_json = self.nodeos.processUrllibRequest(resource, command, payload) - self.assertEqual(ret_json["code"], 500) + self.assertEqual(ret_json["code"], 400) # get_abi with empty parameter command = "get_abi" @@ -391,7 +391,7 @@ def test_ChainApi(self) : # get_abi with valid parameter payload = {"account_name":"default"} ret_json = self.nodeos.processUrllibRequest(resource, command, payload) - self.assertEqual(ret_json["code"], 500) + self.assertEqual(ret_json["code"], 400) # get_raw_code_and_abi with empty parameter command = "get_raw_code_and_abi" @@ -409,7 +409,7 @@ def test_ChainApi(self) : # get_raw_code_and_abi with valid parameter payload = {"account_name":"default"} ret_json = self.nodeos.processUrllibRequest(resource, command, payload) - self.assertEqual(ret_json["code"], 500) + self.assertEqual(ret_json["code"], 400) # get_raw_abi with empty parameter command = "get_raw_abi" @@ -427,7 +427,7 @@ def test_ChainApi(self) : # get_raw_abi with valid parameter payload = {"account_name":"default"} ret_json = self.nodeos.processUrllibRequest(resource, command, payload) - self.assertEqual(ret_json["code"], 500) + self.assertEqual(ret_json["code"], 400) # get_table_rows with empty parameter command = "get_table_rows" @@ -452,7 +452,7 @@ def test_ChainApi(self) : "lower_bound":"0x0000000000000000D0F2A472A8EB6A57", "upper_bound":"0xFFFFFFFFFFFFFFFFD0F2A472A8EB6A57"} ret_json = self.nodeos.processUrllibRequest(resource, command, payload) - self.assertEqual(ret_json["code"], 500) + self.assertEqual(ret_json["code"], 400) # get_table_by_scope with empty parameter command = "get_table_by_scope" @@ -492,7 +492,7 @@ def test_ChainApi(self) : # get_currency_balance with valid parameter payload = {"code":"eosio.token", "account":"unknown"} ret_json = self.nodeos.processUrllibRequest(resource, command, payload) - self.assertEqual(ret_json["code"], 500) + self.assertEqual(ret_json["code"], 400) # get_currency_stats with empty parameter command = "get_currency_stats" @@ -510,7 +510,7 @@ def test_ChainApi(self) : # get_currency_stats with valid parameter payload = {"code":"eosio.token","symbol":"SYS"} ret_json = self.nodeos.processUrllibRequest(resource, command, payload) - self.assertEqual(ret_json["code"], 500) + self.assertEqual(ret_json["code"], 400) # get_producers with empty parameter command = "get_producers"