diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/ResponseParser.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/ResponseParser.kt index 5960f8631..ce8a4299e 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/ResponseParser.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/ResponseParser.kt @@ -164,18 +164,29 @@ abstract class ResponseParser { break } val token = parser.nextToken() - if (token == JsonToken.START_OBJECT) { - inited = true - count++ - continue - } - if (token == JsonToken.END_OBJECT) { - count-- - continue - } - if (token == JsonToken.VALUE_NULL) { - // error is just null - return null + when (token) { + null -> { + return null + } + JsonToken.START_OBJECT -> { + inited = true + count++ + continue + } + JsonToken.END_OBJECT -> { + count-- + continue + } + JsonToken.VALUE_NULL -> { + return null + } + JsonToken.VALUE_STRING -> { + if (!inited) { + message = parser.valueAsString + break + } + } + else -> {} } val field = parser.currentName() if (field == "code" && token == JsonToken.VALUE_NUMBER_INT) { diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/rpcclient/ResponseRpcParserSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/rpcclient/ResponseRpcParserSpec.groovy index f4c4f9be9..5d4796c52 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/rpcclient/ResponseRpcParserSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/rpcclient/ResponseRpcParserSpec.groovy @@ -223,4 +223,16 @@ class ResponseRpcParserSpec extends Specification { !act.hasResult() } + def "Parse non object error"() { + setup: + def json = '{"jsonrpc": "2.0", "id": 1, "error": "plain error"}' + when: + def act = parser.parse(json.getBytes()) + then: + act.error != null + act.error.message == "plain error" + act.hasError() + !act.hasResult() + } + }