From 40461a9752437ee541d797f76d2fba77cad9d0e2 Mon Sep 17 00:00:00 2001 From: imarom Date: Mon, 31 Aug 2015 17:26:08 +0300 Subject: ...draft... --- src/rpc-server/trex_rpc_cmd.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/rpc-server/trex_rpc_cmd.cpp') diff --git a/src/rpc-server/trex_rpc_cmd.cpp b/src/rpc-server/trex_rpc_cmd.cpp index 1ba36e32..6988cba7 100644 --- a/src/rpc-server/trex_rpc_cmd.cpp +++ b/src/rpc-server/trex_rpc_cmd.cpp @@ -26,6 +26,7 @@ TrexRpcCommand::run(const Json::Value ¶ms, Json::Value &result) { /* the internal run can throw a parser error / other error */ try { + check_param_count(params, m_param_count, result); rc = _run(params, result); } catch (TrexRpcCommandException &e) { return e.get_rc(); @@ -40,7 +41,7 @@ TrexRpcCommand::check_param_count(const Json::Value ¶ms, int expected, Json: if (params.size() != expected) { std::stringstream ss; ss << "method expects '" << expected << "' paramteres, '" << params.size() << "' provided"; - generate_err(result, ss.str()); + generate_parse_err(result, ss.str()); } } @@ -177,7 +178,7 @@ TrexRpcCommand::check_field_type_common(const Json::Value &field, const std::str /* first check if field exists */ if (field == Json::Value::null) { ss << "field '" << name << "' is missing"; - generate_err(result, ss.str()); + generate_parse_err(result, ss.str()); } bool rc = true; @@ -232,15 +233,15 @@ TrexRpcCommand::check_field_type_common(const Json::Value &field, const std::str } if (!rc) { ss << "error at offset: " << field.getOffsetStart() << " - '" << name << "' is '" << json_type_to_name(field) << "', expecting '" << type_to_str(type) << "'"; - generate_err(result, ss.str()); + generate_parse_err(result, ss.str()); } } void -TrexRpcCommand::generate_err(Json::Value &result, const std::string &msg) { +TrexRpcCommand::generate_parse_err(Json::Value &result, const std::string &msg) { result["specific_err"] = msg; - throw (TrexRpcCommandException(TREX_RPC_CMD_PARAM_PARSE_ERR)); + throw (TrexRpcCommandException(TREX_RPC_CMD_PARSE_ERR)); } void @@ -249,3 +250,9 @@ TrexRpcCommand::generate_internal_err(Json::Value &result, const std::string &ms throw (TrexRpcCommandException(TREX_RPC_CMD_INTERNAL_ERR)); } +void +TrexRpcCommand::generate_execute_err(Json::Value &result, const std::string &msg) { + result["specific_err"] = msg; + throw (TrexRpcCommandException(TREX_RPC_CMD_EXECUTE_ERR)); +} + -- cgit 1.2.3-korg