Skip to content

Commit

Permalink
rpcdaemon: json streamed request exception handling (#1790)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sixtysixter authored Feb 3, 2024
1 parent 3927cb3 commit ed1b934
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions silkworm/rpc/http/request_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,27 @@ Task<void> RequestHandler::handle_request(commands::RpcApiTable::HandleMethod ha
}

Task<void> RequestHandler::handle_request(commands::RpcApiTable::HandleStream handler, const nlohmann::json& request_json) {
try {
auto io_executor = co_await boost::asio::this_coro::executor;
auto io_executor = co_await boost::asio::this_coro::executor;

try {
co_await channel_->open_stream();
ChunkWriter chunk_writer(*channel_);
json::Stream stream(io_executor, chunk_writer);

co_await (rpc_api_.*handler)(request_json, stream);

try {
co_await (rpc_api_.*handler)(request_json, stream);
} catch (const std::exception& e) {
SILK_ERROR << "exception: " << e.what();
const auto error = make_json_error(request_json, 100, e.what());
stream.write_json(error);
} catch (...) {
SILK_ERROR << "unexpected exception";
const auto error = make_json_error(request_json, 100, "unexpected exception");
stream.write_json(error);
}
co_await stream.close();
} catch (const std::exception& e) {
SILK_ERROR << "exception: " << e.what();
} catch (...) {
SILK_ERROR << "unexpected exception";
}

co_return;
Expand Down

0 comments on commit ed1b934

Please sign in to comment.