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

@ -96,12 +96,16 @@ void http_api_connection::on_request( const fc::http::request& req, const fc::ht
if( var_obj.contains( "method" ) )
{
auto call = var.as<fc::rpc::request>();
try
{
try
{
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 )
{
resp_body = fc::json::to_string( fc::rpc::response( *call.id, error_object{ 1, e.to_detail_string(), fc::variant(e)} ) );

View file

@ -94,6 +94,8 @@ std::string websocket_api_connection::on_message(
{
auto call = var.as<fc::rpc::request>();
exception_ptr optexcept;
try
{
try
{
auto result = _rpc_state.local_call( call.method, call.params );
@ -105,6 +107,8 @@ std::string websocket_api_connection::on_message(
return reply;
}
}
FC_CAPTURE_AND_RETHROW( (call.method)(call.params) )
}
catch ( const fc::exception& e )
{
if( call.id )