Add plugin rpc exception type (#5248)

Signed-off-by: Gabriel-Trintinalia <gabriel.trintinalia@consensys.net>
pull/5250/head
Gabriel-Trintinalia 2 years ago committed by GitHub
parent 8d31050164
commit c55d810321
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/PluginJsonRpcMethod.java
  2. 1
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/response/JsonRpcError.java
  3. 2
      plugin-api/build.gradle
  4. 25
      plugin-api/src/main/java/org/hyperledger/besu/plugin/services/exception/PluginRpcEndpointException.java

@ -15,11 +15,14 @@
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods; package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError.INTERNAL_ERROR; import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError.INTERNAL_ERROR;
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError.PLUGIN_INTERNAL_ERROR;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; 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.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
import org.hyperledger.besu.plugin.services.exception.PluginRpcEndpointException;
import org.hyperledger.besu.plugin.services.rpc.PluginRpcRequest; import org.hyperledger.besu.plugin.services.rpc.PluginRpcRequest;
import java.util.function.Function; import java.util.function.Function;
@ -47,9 +50,14 @@ public class PluginJsonRpcMethod implements JsonRpcMethod {
@Override @Override
public JsonRpcResponse response(final JsonRpcRequestContext request) { public JsonRpcResponse response(final JsonRpcRequestContext request) {
try { try {
Object result = function.apply(() -> request.getRequest().getParams()); final Object result = function.apply(() -> request.getRequest().getParams());
return new JsonRpcSuccessResponse(request.getRequest().getId(), result); return new JsonRpcSuccessResponse(request.getRequest().getId(), result);
} catch (Exception ex) { } catch (final PluginRpcEndpointException ex) {
final JsonRpcError error = PLUGIN_INTERNAL_ERROR;
error.setData(ex.getMessage());
LOG.error("Error calling plugin JSON-RPC endpoint", ex);
return new JsonRpcErrorResponse(request.getRequest().getId(), error);
} catch (final Exception ex) {
LOG.error("Error calling plugin JSON-RPC endpoint", ex); LOG.error("Error calling plugin JSON-RPC endpoint", ex);
return new JsonRpcErrorResponse(request.getRequest().getId(), INTERNAL_ERROR); return new JsonRpcErrorResponse(request.getRequest().getId(), INTERNAL_ERROR);
} }

@ -213,6 +213,7 @@ public enum JsonRpcError {
/** Plugins error */ /** Plugins error */
PLUGIN_NOT_FOUND(-60000, "Plugin not found"), PLUGIN_NOT_FOUND(-60000, "Plugin not found"),
PLUGIN_INTERNAL_ERROR(-32603, "Plugin internal error"),
// Retesteth Errors // Retesteth Errors

@ -67,7 +67,7 @@ Calculated : ${currentHash}
tasks.register('checkAPIChanges', FileStateChecker) { tasks.register('checkAPIChanges', FileStateChecker) {
description = "Checks that the API for the Plugin-API project does not change without deliberate thought" description = "Checks that the API for the Plugin-API project does not change without deliberate thought"
files = sourceSets.main.allJava.files files = sourceSets.main.allJava.files
knownHash = 'sMLZpz/Rie6f/uUFwxaDvVHU8F61pcLnazAfIVwyyH0=' knownHash = '9FHwr8juEGZBU6+nCdHINFIJO7fetydF4AhMZzkOxIs='
} }
check.dependsOn('checkAPIChanges') check.dependsOn('checkAPIChanges')

@ -0,0 +1,25 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.plugin.services.exception;
public class PluginRpcEndpointException extends RuntimeException {
public PluginRpcEndpointException(final String message) {
super(message);
}
public PluginRpcEndpointException(final String message, final Throwable throwable) {
super(message, throwable);
}
}
Loading…
Cancel
Save