From d9c7db51af46e2e76fd4b5134e89587a12db2e5b Mon Sep 17 00:00:00 2001 From: Tom Ritchford Date: Thu, 20 Nov 2014 16:52:20 -0500 Subject: [PATCH] Make three ErrorCode functions generic. --- src/ripple/protocol/JsonFields.h | 4 +++- src/ripple/rpc/ErrorCodes.h | 30 ++++++++++++++++++++++++++---- src/ripple/rpc/impl/ErrorCodes.cpp | 16 ---------------- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/ripple/protocol/JsonFields.h b/src/ripple/protocol/JsonFields.h index 546236c06..bcdb2b522 100644 --- a/src/ripple/protocol/JsonFields.h +++ b/src/ripple/protocol/JsonFields.h @@ -34,9 +34,9 @@ namespace jss { // TODO Move the string not part of the JSON-RPC API into another file JSS ( accepted ); JSS ( account ); -JSS ( accounts ); JSS ( account_hash ); JSS ( account_index ); +JSS ( accounts ); JSS ( accountState ); JSS ( accountTreeHash ); JSS ( affected ); @@ -70,7 +70,9 @@ JSS ( engine_result ); JSS ( engine_result_code ); JSS ( engine_result_message ); JSS ( error ); +JSS ( error_code ); JSS ( error_exception ); +JSS ( error_message ); JSS ( fee_base ); JSS ( fee_ref ); JSS ( fetch_pack ); diff --git a/src/ripple/rpc/ErrorCodes.h b/src/ripple/rpc/ErrorCodes.h index ed9d9dc0a..d39388b27 100644 --- a/src/ripple/rpc/ErrorCodes.h +++ b/src/ripple/rpc/ErrorCodes.h @@ -20,6 +20,7 @@ #ifndef RIPPLE_RPC_ERRORCODES_H_INCLUDED #define RIPPLE_RPC_ERRORCODES_H_INCLUDED +#include #include namespace ripple { @@ -139,10 +140,31 @@ ErrorInfo const& get_error_info (error_code_i code); /** Add or update the json update to reflect the error code. */ /** @{ */ -void inject_error (error_code_i code, Json::Value& json); -inline void inject_error (int code, Json::Value& json) - { inject_error (error_code_i (code), json); } -void inject_error (error_code_i code, std::string const& message, Json::Value& json); +template +void inject_error (error_code_i code, JsonValue& json) +{ + ErrorInfo const& info (get_error_info (code)); + json [jss::error] = info.token; + json [jss::error_code] = info.code; + json [jss::error_message] = info.message; +} + +template +void inject_error (int code, JsonValue& json) +{ + inject_error (error_code_i (code), json); +} + +template +void inject_error ( + error_code_i code, std::string const& message, JsonValue& json) +{ + ErrorInfo const& info (get_error_info (code)); + json [jss::error] = info.token; + json [jss::error_code] = info.code; + json [jss::error_message] = message; +} + /** @} */ /** Returns a new json object that reflects the error code. */ diff --git a/src/ripple/rpc/impl/ErrorCodes.cpp b/src/ripple/rpc/impl/ErrorCodes.cpp index 20059b2d2..1ef219fd6 100644 --- a/src/ripple/rpc/impl/ErrorCodes.cpp +++ b/src/ripple/rpc/impl/ErrorCodes.cpp @@ -149,22 +149,6 @@ ErrorInfo const& get_error_info (error_code_i code) return category.get (code); } -void inject_error (error_code_i code, Json::Value& json) -{ - ErrorInfo const& info (get_error_info (code)); - json ["error"] = info.token; - json ["error_code"] = info.code; - json ["error_message"] = info.message; -} - -void inject_error (error_code_i code, std::string const& message, Json::Value& json) -{ - ErrorInfo const& info (get_error_info (code)); - json ["error"] = info.token; - json ["error_code"] = info.code; - json ["error_message"] = message; -} - Json::Value make_error (error_code_i code) { Json::Value json;