Search in sources :

Example 1 with InvalidRequestRPCException

use of org.aion.rpc.errors.RPCExceptions.InvalidRequestRPCException 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

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 RpcError (org.aion.rpc.types.RPCTypes.RpcError)1