diff --git a/include/fc/rpc/state.hpp b/include/fc/rpc/state.hpp index 3c36bcf..e031530 100644 --- a/include/fc/rpc/state.hpp +++ b/include/fc/rpc/state.hpp @@ -23,7 +23,10 @@ namespace fc { namespace rpc { response(){} response( int64_t i, fc::variant r ):id(i),result(r){} response( int64_t i, error_object r ):id(i),error(r){} + response( int64_t i, fc::variant r, string j ):id(i),jsonrpc(j),result(r){} + response( int64_t i, error_object r, string j ):id(i),jsonrpc(j),error(r){} int64_t id = 0; + optional jsonrpc; optional result; optional error; }; @@ -57,4 +60,4 @@ namespace fc { namespace rpc { FC_REFLECT( fc::rpc::request, (id)(method)(params) ); FC_REFLECT( fc::rpc::error_object, (code)(message)(data) ) -FC_REFLECT( fc::rpc::response, (id)(result)(error) ) +FC_REFLECT( fc::rpc::response, (id)(jsonrpc)(result)(error) ) diff --git a/src/exception.cpp b/src/exception.cpp index fef482a..7da6bea 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -156,7 +156,7 @@ namespace fc * and other information that is generally only useful for * developers. */ - string exception::to_detail_string( log_level ll )const + string exception::to_detail_string( log_level ll )const { fc::stringstream ss; ss << variant(my->_code).as_string() <<" " << my->_name << ": " <_what<<"\n"; @@ -174,13 +174,14 @@ namespace fc /** * Generates a user-friendly error report. */ - string exception::to_string( log_level ll )const + string exception::to_string( log_level ll )const { fc::stringstream ss; - ss << what() << " (" << variant(my->_code).as_string() <<")\n"; + ss << what() << ":"; for( auto itr = my->_elog.begin(); itr != my->_elog.end(); ++itr ) { - ss << fc::format_string( itr->get_format(), itr->get_data() ) <<"\n"; + if( itr->get_format().size() ) + ss << " " << fc::format_string( itr->get_format(), itr->get_data() ); // ss << " " << itr->get_context().to_string() <<"\n"; } return ss.str(); diff --git a/src/rpc/websocket_api.cpp b/src/rpc/websocket_api.cpp index 5f86474..fe95d8c 100644 --- a/src/rpc/websocket_api.cpp +++ b/src/rpc/websocket_api.cpp @@ -90,6 +90,7 @@ std::string websocket_api_connection::on_message( { auto var = fc::json::from_string(message); const auto& var_obj = var.get_object(); + if( var_obj.contains( "method" ) ) { auto call = var.as(); @@ -115,7 +116,7 @@ std::string websocket_api_connection::on_message( if( call.id ) { - auto reply = fc::json::to_string( response( *call.id, result ) ); + auto reply = fc::json::to_string( response( *call.id, result, "2.0" ) ); if( send_message ) _connection.send_message( reply ); return reply; @@ -132,7 +133,7 @@ std::string websocket_api_connection::on_message( } if( optexcept ) { - auto reply = fc::json::to_string( response( *call.id, error_object{ 1, optexcept->to_detail_string(), fc::variant(*optexcept)} ) ); + auto reply = fc::json::to_string( response( *call.id, error_object{ 1, optexcept->to_string(), fc::variant(*optexcept)}, "2.0" ) ); if( send_message ) _connection.send_message( reply );