Search in sources :

Example 1 with RpcError

use of org.aion.rpc.types.RPCTypes.RpcError in project aion by aionnetwork.

the class Web3EntryPointTest method testFailCall.

@Test
public void testFailCall() {
    String response = web3EntryPoint.call("{\"jsonRPC\":\"2.0\",\"method\":\"personal_eecover\",\"params\": [\"0x48656c6c6f20576f726c64\",\"0x7a142a509e6a5e41f82c2e3efb94b05f2a5ba371c8360b58f0ad7b20cd6f8288282f36ab908e5222b8c359d3cc0bacc5f155a952a7a25a1c7c10721b144f134c29e4bb1d31ed3f2642ca1f35acb36c297958a593775f98e7048afc4a1a72de0d\"]}");
    RpcError error = ResponseConverter.decode(response).error;
    assertNotNull(error);
    assertEquals(MethodNotFoundRPCException.INSTANCE.getMessage(), RpcErrorConverter.encodeStr(error));
}
Also used : RpcError(org.aion.rpc.types.RPCTypes.RpcError) Test(org.junit.Test)

Example 2 with RpcError

use of org.aion.rpc.types.RPCTypes.RpcError in project aion by aionnetwork.

the class Web3EntryPoint method call.

public String call(String requestString) {
    logger.debug("Received request: {}", requestString);
    Request request = null;
    RpcError err = null;
    Integer id = null;
    Object resultUnion = null;
    Stopwatch stopwatch = null;
    if (logger.isDebugEnabled()) {
        stopwatch = Stopwatch.createStarted();
    }
    try {
        request = readRequest(requestString);
        id = request.id;
        if (checkMethod(request.method)) {
            resultUnion = RPCServerMethods.execute(request, rpc);
        } else {
            logger.debug("Request attempted to call a method on a disabled interface: {}", request.method);
            err = InvalidRequestRPCException.INSTANCE.getError();
        }
    } catch (InvalidRequestRPCException e) {
        // Don't log this error since it may already be logged elsewhere
        err = e.getError();
    } catch (RPCException e) {
        logger.debug("Request failed due to an RPC exception: {}", e.getMessage());
        err = e.getError();
    } catch (Exception e) {
        logger.error("Call to {} failed.", request == null ? "null" : request.method);
        logger.error("Request failed due to an internal error: ", e);
        err = new InternalErrorRPCException(e.getClass().getSimpleName() + ":" + e.getMessage()).getError();
    // creating an instance of RpcError
    }
    final String resultString = ResponseConverter.encodeStr(new Response(id, resultUnion, err, VersionType.Version2));
    if (stopwatch != null) {
        logger.debug("Produced response: {}bytes in <{}>ms", resultString.getBytes().length, stopwatch.elapsed().toMillis());
    }
    return resultString;
}
Also used : Response(org.aion.rpc.types.RPCTypes.Response) InternalErrorRPCException(org.aion.rpc.errors.RPCExceptions.InternalErrorRPCException) InvalidRequestRPCException(org.aion.rpc.errors.RPCExceptions.InvalidRequestRPCException) RPCException(org.aion.rpc.errors.RPCExceptions.RPCException) Request(org.aion.rpc.types.RPCTypes.Request) RpcError(org.aion.rpc.types.RPCTypes.RpcError) Stopwatch(com.google.common.base.Stopwatch) InternalErrorRPCException(org.aion.rpc.errors.RPCExceptions.InternalErrorRPCException) InternalErrorRPCException(org.aion.rpc.errors.RPCExceptions.InternalErrorRPCException) InvalidRequestRPCException(org.aion.rpc.errors.RPCExceptions.InvalidRequestRPCException) RPCException(org.aion.rpc.errors.RPCExceptions.RPCException) InvalidRequestRPCException(org.aion.rpc.errors.RPCExceptions.InvalidRequestRPCException)

Aggregations

RpcError (org.aion.rpc.types.RPCTypes.RpcError)2 Stopwatch (com.google.common.base.Stopwatch)1 InternalErrorRPCException (org.aion.rpc.errors.RPCExceptions.InternalErrorRPCException)1 InvalidRequestRPCException (org.aion.rpc.errors.RPCExceptions.InvalidRequestRPCException)1 RPCException (org.aion.rpc.errors.RPCExceptions.RPCException)1 Request (org.aion.rpc.types.RPCTypes.Request)1 Response (org.aion.rpc.types.RPCTypes.Response)1 Test (org.junit.Test)1