diff --git a/rskj-core/src/main/java/org/ethereum/rpc/exception/RskErrorResolver.java b/rskj-core/src/main/java/org/ethereum/rpc/exception/RskErrorResolver.java
index b74bc17cb56..7ec4bd70f62 100644
--- a/rskj-core/src/main/java/org/ethereum/rpc/exception/RskErrorResolver.java
+++ b/rskj-core/src/main/java/org/ethereum/rpc/exception/RskErrorResolver.java
@@ -1,87 +1,77 @@
+/*
+ * This file is part of RskJ
+ * Copyright (C) 2018 RSK Labs Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
package org.ethereum.rpc.exception;
import co.rsk.core.exception.InvalidRskAddressException;
-import co.rsk.jsonrpc.JsonRpcError;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
import com.googlecode.jsonrpc4j.ErrorResolver;
+import org.ethereum.rpc.exception.handlers.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Method;
-import java.util.Iterator;
+import java.util.HashMap;
import java.util.List;
-
-import static javax.xml.bind.DatatypeConverter.printHexBinary;
+import java.util.Map;
/**
* Created by mario on 17/10/2016.
*/
public class RskErrorResolver implements ErrorResolver {
+ private final Map, Class extends RskErrorHandler>> errorHandlers;
- private static final Logger logger = LoggerFactory.getLogger("web3");
+ public RskErrorResolver() {
+ errorHandlers = new HashMap<>();
+ errorHandlers.put(InvalidRskAddressException.class, InvalidRskAddressExceptionHandler.class);
+ errorHandlers.put(RskJsonRpcRequestException.class, RskJsonRpcRequestExceptionHandler.class);
+ errorHandlers.put(InvalidFormatException.class, InvalidFormatExceptionHandler.class);
+ errorHandlers.put(UnrecognizedPropertyException.class, UnrecognizedPropertyExceptionHandler.class);
+ errorHandlers.put(UnsupportedOperationException.class, UnsupportedOperationExceptionHandler.class);
+ }
- @Override
- public JsonError resolveError(Throwable t, Method method, List arguments) {
- JsonError error;
- if (t instanceof InvalidRskAddressException) {
- error = new JsonError(
- JsonRpcError.INVALID_PARAMS,
- "invalid argument 0: hex string has length " + arguments.get(0).asText().replace("0x", "").length() + ", want 40 for RSK address",
- null);
- } else if (t instanceof RskJsonRpcRequestException) {
- RskJsonRpcRequestException rskJsonRpcRequestException = (RskJsonRpcRequestException) t;
- byte[] revertData = rskJsonRpcRequestException.getRevertData();
- String errorDataHexString = "0x" + printHexBinary(revertData == null ? new byte[]{} : revertData).toLowerCase();
- error = new JsonError(rskJsonRpcRequestException.getCode(), t.getMessage(), errorDataHexString);
- } else if (t instanceof InvalidFormatException) {
- error = new JsonError(JsonRpcError.INTERNAL_ERROR, "Internal server error, probably due to invalid parameter type", null);
- } else if (t instanceof UnrecognizedPropertyException) {
- error = new JsonError(
- JsonRpcError.INVALID_PARAMS,
- getExceptionMessage((UnrecognizedPropertyException) t),
- null);
- } else if (t instanceof JsonMappingException && t.getMessage().contains("Can not construct instance")) {
- error = new JsonError(
- JsonRpcError.INVALID_PARAMS,
- "invalid argument 0: json: cannot unmarshal string into value of input",
- null);
- } else if (t instanceof UnsupportedOperationException || (t.getMessage() != null && t.getMessage().toLowerCase().contains("method not supported"))) {
- error = new JsonError(
- JsonRpcError.METHOD_NOT_FOUND,
- "the method " + method.getName() + " does not exist/is not available",
- null);
- } else {
- logger.error("JsonRPC error when for method {} with arguments {}", method, arguments, t);
- error = new JsonError(JsonRpcError.INTERNAL_ERROR, "Internal server error", null);
- }
- return error;
- }
+ private static final Logger web3Logger = LoggerFactory.getLogger("web3");
- private static String getExceptionMessage(UnrecognizedPropertyException ex) {
- if (ex.getPropertyName() == null || ex.getKnownPropertyIds() == null) return "Invalid parameters";
+ @Override
+ public JsonError resolveError(Throwable throwable, Method method, List arguments) {
+ if (throwable instanceof JsonMappingException && throwable.getMessage() != null && throwable.getMessage().contains("Can not construct instance")) {
+ return new JsonMappingExceptionHandler(web3Logger).apply(throwable, method, arguments);
+ }
- StringBuilder stringBuilder = new StringBuilder("Unrecognized field \"");
- stringBuilder.append(ex.getPropertyName());
- stringBuilder.append("\" (");
- stringBuilder.append(ex.getKnownPropertyIds().size());
- stringBuilder.append(" known properties: [");
+ if (throwable.getMessage() != null && throwable.getMessage().toLowerCase().contains("method not supported")) {
+ return new UnsupportedOperationExceptionHandler(web3Logger).apply(throwable, method, arguments);
+ }
- Iterator iterator = ex.getKnownPropertyIds().iterator();
- while (iterator.hasNext()) {
- stringBuilder.append("\"");
- stringBuilder.append(iterator.next());
- stringBuilder.append("\"");
- if (iterator.hasNext()) {
- stringBuilder.append(", ");
- }
+ Class extends RskErrorHandler> handlerClass = errorHandlers.get(throwable.getClass());
+ if (handlerClass == null) {
+ return (new DefaultRskErrorHandler(web3Logger)).apply(throwable, method, arguments);
}
- stringBuilder.append("])");
+ RskErrorHandler handler;
+ try {
+ handler = handlerClass.getDeclaredConstructor(Logger.class).newInstance(web3Logger);
+ } catch (Exception exception) {
+ return (new DefaultRskErrorHandler(web3Logger)).apply(throwable, method, arguments);
+ }
- return stringBuilder.toString();
+ return handler.apply(throwable, method, arguments);
}
}
diff --git a/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/BaseRskErrorHandler.java b/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/BaseRskErrorHandler.java
new file mode 100644
index 00000000000..cd8c7aa6a24
--- /dev/null
+++ b/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/BaseRskErrorHandler.java
@@ -0,0 +1,61 @@
+/*
+ * This file is part of RskJ
+ * Copyright (C) 2018 RSK Labs Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+package org.ethereum.rpc.exception.handlers;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
+import org.slf4j.Logger;
+
+import java.lang.reflect.Method;
+import java.util.Iterator;
+import java.util.List;
+
+public abstract class BaseRskErrorHandler implements RskErrorHandler {
+ protected final Logger logger;
+
+ public BaseRskErrorHandler(Logger logger) {
+ this.logger = logger;
+ }
+
+ protected void logJsonRPCError(Throwable throwable, Method method, List arguments) {
+ logger.error("JsonRPC error for method {} with arguments {}", method, arguments, throwable);
+ }
+
+ protected static String getExceptionMessage(UnrecognizedPropertyException ex) {
+ if (ex.getPropertyName() == null || ex.getKnownPropertyIds() == null) return "Invalid parameters";
+
+ StringBuilder stringBuilder = new StringBuilder("Unrecognized field \"");
+ stringBuilder.append(ex.getPropertyName());
+ stringBuilder.append("\" (");
+ stringBuilder.append(ex.getKnownPropertyIds().size());
+ stringBuilder.append(" known properties: [");
+
+ Iterator iterator = ex.getKnownPropertyIds().iterator();
+ while (iterator.hasNext()) {
+ stringBuilder.append("\"");
+ stringBuilder.append(iterator.next());
+ stringBuilder.append("\"");
+ if (iterator.hasNext()) {
+ stringBuilder.append(", ");
+ }
+ }
+ stringBuilder.append("])");
+
+ return stringBuilder.toString();
+ }
+}
diff --git a/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/DefaultRskErrorHandler.java b/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/DefaultRskErrorHandler.java
new file mode 100644
index 00000000000..630b5a95d97
--- /dev/null
+++ b/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/DefaultRskErrorHandler.java
@@ -0,0 +1,37 @@
+/*
+ * This file is part of RskJ
+ * Copyright (C) 2018 RSK Labs Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+package org.ethereum.rpc.exception.handlers;
+
+import co.rsk.jsonrpc.JsonRpcError;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.googlecode.jsonrpc4j.ErrorResolver;
+import org.slf4j.Logger;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+public class DefaultRskErrorHandler extends BaseRskErrorHandler {
+ public DefaultRskErrorHandler(Logger logger) {
+ super(logger);
+ }
+
+ public ErrorResolver.JsonError apply(Throwable throwable, Method method, List arguments) {
+ logJsonRPCError(throwable, method, arguments);
+ return new ErrorResolver.JsonError(JsonRpcError.INTERNAL_ERROR, "Internal server error", null);
+ };
+}
diff --git a/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/InvalidFormatExceptionHandler.java b/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/InvalidFormatExceptionHandler.java
new file mode 100644
index 00000000000..7b4d67d349b
--- /dev/null
+++ b/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/InvalidFormatExceptionHandler.java
@@ -0,0 +1,39 @@
+/*
+ * This file is part of RskJ
+ * Copyright (C) 2018 RSK Labs Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+package org.ethereum.rpc.exception.handlers;
+
+import co.rsk.jsonrpc.JsonRpcError;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.googlecode.jsonrpc4j.ErrorResolver;
+import org.slf4j.Logger;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+public class InvalidFormatExceptionHandler extends BaseRskErrorHandler {
+ public InvalidFormatExceptionHandler(Logger logger) {
+ super(logger);
+ }
+
+ @Override
+ public ErrorResolver.JsonError apply(Throwable throwable, Method method, List arguments) {
+ logJsonRPCError(throwable, method, arguments);
+
+ return new ErrorResolver.JsonError(JsonRpcError.INTERNAL_ERROR, "Internal server error, probably due to invalid parameter type", null);
+ }
+}
diff --git a/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/InvalidRskAddressExceptionHandler.java b/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/InvalidRskAddressExceptionHandler.java
new file mode 100644
index 00000000000..c8dee6bb4a4
--- /dev/null
+++ b/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/InvalidRskAddressExceptionHandler.java
@@ -0,0 +1,42 @@
+/*
+ * This file is part of RskJ
+ * Copyright (C) 2018 RSK Labs Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+package org.ethereum.rpc.exception.handlers;
+
+import co.rsk.jsonrpc.JsonRpcError;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.googlecode.jsonrpc4j.ErrorResolver.JsonError;
+import org.slf4j.Logger;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+public class InvalidRskAddressExceptionHandler extends BaseRskErrorHandler {
+ public InvalidRskAddressExceptionHandler(Logger logger) {
+ super(logger);
+ }
+
+ @Override
+ public JsonError apply(Throwable throwable, Method method, List arguments) {
+ logJsonRPCError(throwable, method, arguments);
+
+ return new JsonError(
+ JsonRpcError.INVALID_PARAMS,
+ "invalid argument 0: hex string has length " + arguments.get(0).asText().replace("0x", "").length() + ", want 40 for RSK address",
+ null);
+ }
+}
diff --git a/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/JsonMappingExceptionHandler.java b/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/JsonMappingExceptionHandler.java
new file mode 100644
index 00000000000..99c4ca089d7
--- /dev/null
+++ b/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/JsonMappingExceptionHandler.java
@@ -0,0 +1,42 @@
+/*
+ * This file is part of RskJ
+ * Copyright (C) 2018 RSK Labs Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+package org.ethereum.rpc.exception.handlers;
+
+import co.rsk.jsonrpc.JsonRpcError;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.googlecode.jsonrpc4j.ErrorResolver;
+import org.slf4j.Logger;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+public class JsonMappingExceptionHandler extends BaseRskErrorHandler {
+ public JsonMappingExceptionHandler(Logger web3Logger) {
+ super(web3Logger);
+ }
+
+ @Override
+ public ErrorResolver.JsonError apply(Throwable throwable, Method method, List arguments) {
+ logJsonRPCError(throwable, method, arguments);
+
+ return new ErrorResolver.JsonError(
+ JsonRpcError.INVALID_PARAMS,
+ "invalid argument 0: json: cannot unmarshal string into value of input",
+ null);
+ }
+}
diff --git a/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/RskErrorHandler.java b/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/RskErrorHandler.java
new file mode 100644
index 00000000000..1c32dbeac92
--- /dev/null
+++ b/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/RskErrorHandler.java
@@ -0,0 +1,28 @@
+/*
+ * This file is part of RskJ
+ * Copyright (C) 2018 RSK Labs Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+package org.ethereum.rpc.exception.handlers;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.googlecode.jsonrpc4j.ErrorResolver.JsonError;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+public interface RskErrorHandler {
+ JsonError apply(Throwable throwable, Method method, List arguments);
+}
diff --git a/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/RskJsonRpcRequestExceptionHandler.java b/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/RskJsonRpcRequestExceptionHandler.java
new file mode 100644
index 00000000000..88c3d2f87b4
--- /dev/null
+++ b/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/RskJsonRpcRequestExceptionHandler.java
@@ -0,0 +1,44 @@
+/*
+ * This file is part of RskJ
+ * Copyright (C) 2018 RSK Labs Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+package org.ethereum.rpc.exception.handlers;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.googlecode.jsonrpc4j.ErrorResolver;
+import org.ethereum.rpc.exception.RskJsonRpcRequestException;
+import org.slf4j.Logger;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+import static javax.xml.bind.DatatypeConverter.printHexBinary;
+
+public class RskJsonRpcRequestExceptionHandler extends BaseRskErrorHandler {
+ public RskJsonRpcRequestExceptionHandler(Logger logger) {
+ super(logger);
+ }
+
+ @Override
+ public ErrorResolver.JsonError apply(Throwable throwable, Method method, List arguments) {
+ logJsonRPCError(throwable, method, arguments);
+ RskJsonRpcRequestException rskJsonRpcRequestException = (RskJsonRpcRequestException) throwable;
+ byte[] revertData = rskJsonRpcRequestException.getRevertData();
+ String errorDataHexString = "0x" + printHexBinary(revertData == null ? new byte[]{} : revertData).toLowerCase();
+
+ return new ErrorResolver.JsonError(rskJsonRpcRequestException.getCode(), throwable.getMessage(), errorDataHexString);
+ }
+}
diff --git a/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/UnrecognizedPropertyExceptionHandler.java b/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/UnrecognizedPropertyExceptionHandler.java
new file mode 100644
index 00000000000..886cfc21d4c
--- /dev/null
+++ b/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/UnrecognizedPropertyExceptionHandler.java
@@ -0,0 +1,43 @@
+/*
+ * This file is part of RskJ
+ * Copyright (C) 2018 RSK Labs Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+package org.ethereum.rpc.exception.handlers;
+
+import co.rsk.jsonrpc.JsonRpcError;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
+import com.googlecode.jsonrpc4j.ErrorResolver;
+import org.slf4j.Logger;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+public class UnrecognizedPropertyExceptionHandler extends BaseRskErrorHandler {
+ public UnrecognizedPropertyExceptionHandler(Logger logger) {
+ super(logger);
+ }
+
+ @Override
+ public ErrorResolver.JsonError apply(Throwable throwable, Method method, List arguments) {
+ logJsonRPCError(throwable, method, arguments);
+
+ return new ErrorResolver.JsonError(
+ JsonRpcError.INVALID_PARAMS,
+ getExceptionMessage((UnrecognizedPropertyException) throwable),
+ null);
+ }
+}
diff --git a/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/UnsupportedOperationExceptionHandler.java b/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/UnsupportedOperationExceptionHandler.java
new file mode 100644
index 00000000000..50120ffb050
--- /dev/null
+++ b/rskj-core/src/main/java/org/ethereum/rpc/exception/handlers/UnsupportedOperationExceptionHandler.java
@@ -0,0 +1,42 @@
+/*
+ * This file is part of RskJ
+ * Copyright (C) 2018 RSK Labs Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+package org.ethereum.rpc.exception.handlers;
+
+import co.rsk.jsonrpc.JsonRpcError;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.googlecode.jsonrpc4j.ErrorResolver;
+import org.slf4j.Logger;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+public class UnsupportedOperationExceptionHandler extends BaseRskErrorHandler {
+ public UnsupportedOperationExceptionHandler(Logger logger) {
+ super(logger);
+ }
+
+ @Override
+ public ErrorResolver.JsonError apply(Throwable throwable, Method method, List arguments) {
+ logJsonRPCError(throwable, method, arguments);
+
+ return new ErrorResolver.JsonError(
+ JsonRpcError.METHOD_NOT_FOUND,
+ "the method " + method.getName() + " does not exist/is not available",
+ null);
+ }
+}
diff --git a/rskj-core/src/test/java/org/ethereum/rpc/exception/RskErrorResolverTest.java b/rskj-core/src/test/java/org/ethereum/rpc/exception/RskErrorResolverTest.java
index 7a76a2cf54c..004f4b4e5c3 100644
--- a/rskj-core/src/test/java/org/ethereum/rpc/exception/RskErrorResolverTest.java
+++ b/rskj-core/src/test/java/org/ethereum/rpc/exception/RskErrorResolverTest.java
@@ -1,6 +1,7 @@
package org.ethereum.rpc.exception;
import co.rsk.core.exception.InvalidRskAddressException;
+import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
@@ -89,7 +90,12 @@ void test_resolveError_givenRskJsonRpcRequestExceptionWithData_returnsJsonErrorW
@Test
void test_resolveError_givenInvalidFormatException_returnsJsonErrorAsExpected() throws NoSuchMethodException {
// Given
- InvalidFormatException exception = mock(InvalidFormatException.class);
+ InvalidFormatException exception = new InvalidFormatException(
+ mock(JsonParser.class),
+ "",
+ new byte[]{},
+ Exception.class
+ );
Method methodMock = this.getClass().getMethod("mockMethod");
List jsonNodeListMock = new ArrayList<>();