Skip to content

Commit fa63cd7

Browse files
author
Michael Vandeberg
committed
Responses contain jsonrpc field and increased readability of errors bitshares#13
1 parent 5cfcb5c commit fa63cd7

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

include/fc/rpc/state.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ namespace fc { namespace rpc {
2323
response(){}
2424
response( int64_t i, fc::variant r ):id(i),result(r){}
2525
response( int64_t i, error_object r ):id(i),error(r){}
26+
response( int64_t i, fc::variant r, string j ):id(i),jsonrpc(j),result(r){}
27+
response( int64_t i, error_object r, string j ):id(i),jsonrpc(j),error(r){}
2628
int64_t id = 0;
29+
optional<fc::string> jsonrpc;
2730
optional<fc::variant> result;
2831
optional<error_object> error;
2932
};
@@ -57,4 +60,4 @@ namespace fc { namespace rpc {
5760

5861
FC_REFLECT( fc::rpc::request, (id)(method)(params) );
5962
FC_REFLECT( fc::rpc::error_object, (code)(message)(data) )
60-
FC_REFLECT( fc::rpc::response, (id)(result)(error) )
63+
FC_REFLECT( fc::rpc::response, (id)(jsonrpc)(result)(error) )

src/exception.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ namespace fc
156156
* and other information that is generally only useful for
157157
* developers.
158158
*/
159-
string exception::to_detail_string( log_level ll )const
159+
string exception::to_detail_string( log_level ll )const
160160
{
161161
fc::stringstream ss;
162162
ss << variant(my->_code).as_string() <<" " << my->_name << ": " <<my->_what<<"\n";
@@ -174,13 +174,14 @@ namespace fc
174174
/**
175175
* Generates a user-friendly error report.
176176
*/
177-
string exception::to_string( log_level ll )const
177+
string exception::to_string( log_level ll )const
178178
{
179179
fc::stringstream ss;
180-
ss << what() << " (" << variant(my->_code).as_string() <<")\n";
180+
ss << what() << ":";
181181
for( auto itr = my->_elog.begin(); itr != my->_elog.end(); ++itr )
182182
{
183-
ss << fc::format_string( itr->get_format(), itr->get_data() ) <<"\n";
183+
if( itr->get_format().size() )
184+
ss << " " << fc::format_string( itr->get_format(), itr->get_data() );
184185
// ss << " " << itr->get_context().to_string() <<"\n";
185186
}
186187
return ss.str();

src/rpc/websocket_api.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ std::string websocket_api_connection::on_message(
9090
{
9191
auto var = fc::json::from_string(message);
9292
const auto& var_obj = var.get_object();
93+
9394
if( var_obj.contains( "method" ) )
9495
{
9596
auto call = var.as<fc::rpc::request>();
@@ -115,7 +116,7 @@ std::string websocket_api_connection::on_message(
115116

116117
if( call.id )
117118
{
118-
auto reply = fc::json::to_string( response( *call.id, result ) );
119+
auto reply = fc::json::to_string( response( *call.id, result, "2.0" ) );
119120
if( send_message )
120121
_connection.send_message( reply );
121122
return reply;
@@ -132,7 +133,7 @@ std::string websocket_api_connection::on_message(
132133
}
133134
if( optexcept ) {
134135

135-
auto reply = fc::json::to_string( response( *call.id, error_object{ 1, optexcept->to_detail_string(), fc::variant(*optexcept)} ) );
136+
auto reply = fc::json::to_string( response( *call.id, error_object{ 1, optexcept->to_string(), fc::variant(*optexcept)}, "2.0" ) );
136137
if( send_message )
137138
_connection.send_message( reply );
138139

0 commit comments

Comments
 (0)