problem: Proxy doesn't render internal exceptions to JSON RPC errors

This commit is contained in:
Igor Artamonov
2021-10-27 21:18:58 -04:00
parent 133937822c
commit 89eec9958a
2 changed files with 24 additions and 6 deletions

View File

@@ -63,9 +63,6 @@ open class WriteRpcJson {
Mono.empty()
}
}
.onErrorContinue { t, _ ->
log.warn("Failed to convert to JSON", t)
}
}
}

View File

@@ -16,10 +16,8 @@
*/
package io.emeraldpay.dshackle.proxy
import com.google.protobuf.ByteString
import io.emeraldpay.api.proto.BlockchainOuterClass
import io.emeraldpay.dshackle.rpc.NativeCall
import io.emeraldpay.dshackle.test.TestingCommons
import org.jetbrains.annotations.NotNull
import reactor.core.publisher.Flux
import spock.lang.Specification
@@ -143,4 +141,27 @@ class WriteRpcJsonSpec extends Specification {
act[1] == '{"jsonrpc":"2.0","id":11,"error":{"code":-32002,"message":"oops"}}'
act[2] == '{"jsonrpc":"2.0","id":15,"result":{"hash": "0x2484f459dc"}}'
}
def "Write JSON RPC error on exception"() {
setup:
def writer = new WriteRpcJson() {
@Override
String toJson(@NotNull ProxyCall call, @NotNull NativeCall.CallResult response) {
throw new NativeCall.CallFailure(1, new IllegalStateException("TEST"))
}
}
def call = new ProxyCall(ProxyCall.RpcType.SINGLE)
call.ids[1] = 10
def data = [
new NativeCall.CallResult(1, '"0x1"'.bytes, null),
]
when:
def act = Flux.fromIterable(data)
.transform(writer.toJsons(call))
.collectList()
.block(Duration.ofSeconds(1))
then:
act[0] == '{"jsonrpc":"2.0","id":10,"error":{"code":-32003,"message":"TEST"}}'
}
}