Skip to content

Commit

Permalink
5098: Update RpcErrorType.INVALID_ENODE_PARAMS
Browse files Browse the repository at this point in the history
Signed-off-by: Matilda Clerke <[email protected]>
  • Loading branch information
Matilda-Clerke committed Aug 13, 2024
1 parent 20b5a08 commit a70a150
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
Expand Down Expand Up @@ -45,9 +46,6 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
try {
final String enodeString = requestContext.getRequiredParameter(0, String.class);
return performOperation(requestContext.getRequest().getId(), enodeString);
} catch (final InvalidJsonRpcParameters e) {
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS);
} catch (final IllegalArgumentException e) {
if (e.getMessage()
.endsWith(
Expand All @@ -69,6 +67,9 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
} catch (final P2PDisabledException e) {
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), RpcErrorType.P2P_DISABLED);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), RpcErrorType.INVALID_ENODE_PARAMS);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.StringListParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
Expand Down Expand Up @@ -46,8 +48,13 @@ public String getName() {

@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final StringListParameter enodeListParam =
requestContext.getRequiredParameter(0, StringListParameter.class);
final StringListParameter enodeListParam;
try {
enodeListParam = requestContext.getRequiredParameter(0, StringListParameter.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid enode list parameter (index 0)", RpcErrorType.INVALID_ENODE_PARAMS, e);
}

try {
if (nodeAllowlistPermissioningController.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.StringListParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
Expand Down Expand Up @@ -46,8 +48,13 @@ public String getName() {

@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final StringListParameter enodeListParam =
requestContext.getRequiredParameter(0, StringListParameter.class);
final StringListParameter enodeListParam;
try {
enodeListParam = requestContext.getRequiredParameter(0, StringListParameter.class);
} catch (Exception e) { // TODO:replace with JsonRpcParameter.JsonRpcParameterException
throw new InvalidJsonRpcParameters(
"Invalid enode list parameter (index 0)", RpcErrorType.INVALID_ENODE_PARAMS, e);
}
try {
if (nodeAllowlistPermissioningController.isPresent()) {
try {
Expand Down

0 comments on commit a70a150

Please sign in to comment.