From cfc53e8b82417f6c0db4ff67d257cbb49fbb64e4 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Wed, 7 Dec 2016 15:23:38 -0500 Subject: [PATCH] Wrap non-FC exceptions thrown by client methods --- src/rpc/http_api.cpp | 10 +++++++--- src/rpc/websocket_api.cpp | 16 ++++++++++------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/rpc/http_api.cpp b/src/rpc/http_api.cpp index c9a7786..281febd 100644 --- a/src/rpc/http_api.cpp +++ b/src/rpc/http_api.cpp @@ -98,9 +98,13 @@ void http_api_connection::on_request( const fc::http::request& req, const fc::ht auto call = var.as(); 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; + 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 ) { diff --git a/src/rpc/websocket_api.cpp b/src/rpc/websocket_api.cpp index 60ef706..0ff9304 100644 --- a/src/rpc/websocket_api.cpp +++ b/src/rpc/websocket_api.cpp @@ -96,14 +96,18 @@ std::string websocket_api_connection::on_message( exception_ptr optexcept; try { - auto result = _rpc_state.local_call( call.method, call.params ); - if( call.id ) + try { - auto reply = fc::json::to_string( response( *call.id, result ) ); - if( send_message ) - _connection.send_message( reply ); - return reply; + auto result = _rpc_state.local_call( call.method, call.params ); + if( call.id ) + { + 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 ) {