Merge pull request #6 from steemit/rpc-catch-all

Wrap non-FC exceptions thrown by client methods
This commit is contained in:
theoreticalbts 2016-12-22 12:48:02 -05:00 committed by GitHub
commit d37811afdf
2 changed files with 17 additions and 9 deletions

View file

@ -98,9 +98,13 @@ void http_api_connection::on_request( const fc::http::request& req, const fc::ht
auto call = var.as<fc::rpc::request>(); auto call = var.as<fc::rpc::request>();
try try
{ {
auto result = _rpc_state.local_call( call.method, call.params ); try
resp_body = fc::json::to_string( fc::rpc::response( *call.id, result ) ); {
resp_status = http::reply::OK; auto result = _rpc_state.local_call( call.method, call.params );
resp_body = fc::json::to_string( fc::rpc::response( *call.id, result ) );
resp_status = http::reply::OK;
}
FC_CAPTURE_AND_RETHROW( (call.method)(call.params) );
} }
catch ( const fc::exception& e ) catch ( const fc::exception& e )
{ {

View file

@ -96,14 +96,18 @@ std::string websocket_api_connection::on_message(
exception_ptr optexcept; exception_ptr optexcept;
try try
{ {
auto result = _rpc_state.local_call( call.method, call.params ); try
if( call.id )
{ {
auto reply = fc::json::to_string( response( *call.id, result ) ); auto result = _rpc_state.local_call( call.method, call.params );
if( send_message ) if( call.id )
_connection.send_message( reply ); {
return reply; auto reply = fc::json::to_string( response( *call.id, result ) );
if( send_message )
_connection.send_message( reply );
return reply;
}
} }
FC_CAPTURE_AND_RETHROW( (call.method)(call.params) )
} }
catch ( const fc::exception& e ) catch ( const fc::exception& e )
{ {