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));
}
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;
}
Aggregations