Skip to content

Commit

Permalink
rpcdaemon: trap einval exception to manage block not found (#2352)
Browse files Browse the repository at this point in the history
  • Loading branch information
lupin012 committed Sep 16, 2024
1 parent 1b32475 commit 59a397c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions silkworm/rpc/commands/erigon_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ Task<void> ErigonRpcApi::handle_erigon_get_header_by_hash(const nlohmann::json&
} else {
reply = make_json_content(request, *header);
}
} catch (const std::invalid_argument& iv) {
reply = make_json_error(request, kServerError, "block header not found: 0x" + silkworm::to_hex(block_hash));
} catch (const std::exception& e) {
SILK_ERROR << "exception: " << e.what() << " processing request: " << request.dump();
reply = make_json_error(request, kInternalError, e.what());
Expand Down Expand Up @@ -423,6 +425,8 @@ Task<void> ErigonRpcApi::handle_erigon_get_logs_by_hash(const nlohmann::json& re
SILK_DEBUG << "logs.size(): " << logs.size();

reply = make_json_content(request, logs);
} catch (const std::invalid_argument& iv) {
reply = make_json_content(request, nullptr);
} catch (const std::exception& e) {
SILK_ERROR << "exception: " << e.what() << " processing request: " << request.dump();
reply = make_json_error(request, kInternalError, e.what());
Expand Down
2 changes: 2 additions & 0 deletions silkworm/rpc/commands/eth_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ Task<void> EthereumRpcApi::handle_eth_get_uncle_count_by_block_hash(const nlohma
const auto ommers = block_with_hash->block.ommers.size();
reply = make_json_content(request, to_quantity(ommers));
}
} catch (const std::invalid_argument& iv) {
reply = make_json_content(request, nullptr);
} catch (const std::exception& e) {
SILK_ERROR << "exception: " << e.what() << " processing request: " << request.dump();
reply = make_json_error(request, kInternalError, e.what());
Expand Down

0 comments on commit 59a397c

Please sign in to comment.