Add Rpc method name when logging IOException (#4406)

* Add Rpc method name when logging IOException

Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>

* Simplify syntax of the logged message

Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>

Signed-off-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
Co-authored-by: Gabriel Trintinalia <gabriel.trintinalia@consensys.net>
pull/4478/head
Gabriel-Trintinalia 2 years ago committed by GitHub
parent 7ae6edda8f
commit 4c66cc69cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      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();

Loading…
Cancel
Save