Skip to content

Commit ed1b934

Browse files
authored
rpcdaemon: json streamed request exception handling (#1790)
1 parent 3927cb3 commit ed1b934

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

silkworm/rpc/http/request_handler.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,27 @@ Task<void> RequestHandler::handle_request(commands::RpcApiTable::HandleMethod ha
158158
}
159159

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

163+
try {
164164
co_await channel_->open_stream();
165165
ChunkWriter chunk_writer(*channel_);
166166
json::Stream stream(io_executor, chunk_writer);
167167

168-
co_await (rpc_api_.*handler)(request_json, stream);
169-
168+
try {
169+
co_await (rpc_api_.*handler)(request_json, stream);
170+
} catch (const std::exception& e) {
171+
SILK_ERROR << "exception: " << e.what();
172+
const auto error = make_json_error(request_json, 100, e.what());
173+
stream.write_json(error);
174+
} catch (...) {
175+
SILK_ERROR << "unexpected exception";
176+
const auto error = make_json_error(request_json, 100, "unexpected exception");
177+
stream.write_json(error);
178+
}
170179
co_await stream.close();
171180
} catch (const std::exception& e) {
172181
SILK_ERROR << "exception: " << e.what();
173-
} catch (...) {
174-
SILK_ERROR << "unexpected exception";
175182
}
176183

177184
co_return;

0 commit comments

Comments
 (0)