From 4c66cc69cff5fc20ccc258ea4959111497d8fa09 Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Tue, 4 Oct 2022 14:40:07 +1100 Subject: [PATCH] Add Rpc method name when logging IOException (#4406) * Add Rpc method name when logging IOException Signed-off-by: Gabriel Trintinalia * Simplify syntax of the logged message Signed-off-by: Gabriel Trintinalia Signed-off-by: Gabriel Trintinalia Co-authored-by: Gabriel Trintinalia --- .../api/handlers/JsonRpcExecutorHandler.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/JsonRpcExecutorHandler.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/JsonRpcExecutorHandler.java index 273b9278ab..4032a731a1 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/JsonRpcExecutorHandler.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/handlers/JsonRpcExecutorHandler.java @@ -133,14 +133,24 @@ public class JsonRpcExecutorHandler { } else { handleJsonRpcError(ctx, null, JsonRpcError.PARSE_ERROR); } - } catch (IOException ex) { - LOG.error("Error streaming JSON-RPC response", ex); - } catch (RuntimeException e) { + } catch (final IOException ex) { + final String method = getRpcMethodName(ctx); + LOG.error("{} - Error streaming JSON-RPC response", method, ex); + } catch (final RuntimeException e) { handleJsonRpcError(ctx, null, JsonRpcError.INTERNAL_ERROR); } }; } + private static String getRpcMethodName(final RoutingContext ctx) { + if (ctx.data().containsKey(ContextKey.REQUEST_BODY_AS_JSON_OBJECT.name())) { + final JsonObject jsonObject = ctx.get(ContextKey.REQUEST_BODY_AS_JSON_OBJECT.name()); + return jsonObject.getString("method"); + } else { + return ""; + } + } + private static void handleJsonRpcError( final RoutingContext routingContext, final Object id, final JsonRpcError error) { final HttpServerResponse response = routingContext.response();