Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have to set lenient on JsonReader for RPC #38

Open
hshar7 opened this issue Aug 8, 2018 · 5 comments
Open

Have to set lenient on JsonReader for RPC #38

hshar7 opened this issue Aug 8, 2018 · 5 comments

Comments

@hshar7
Copy link

hshar7 commented Aug 8, 2018

I am trying to connect to a basic auth web3 node. If basic auth fails, it returns back non-json text to say that you're not authenticated..
You have to set leninet = true for moshi to be able to return this text back without the client failing. Or perhaps check if it's json, if not jsonify it before handing it to moshi?

Caused by: com.squareup.moshi.JsonEncodingException: Use JsonReader.setLenient(true) to accept malformed JSON at path $
	at com.squareup.moshi.JsonReader.syntaxError(JsonReader.java:220)
	at com.squareup.moshi.JsonUtf8Reader.checkLenient(JsonUtf8Reader.java:1031)
	at com.squareup.moshi.JsonUtf8Reader.doPeek(JsonUtf8Reader.java:344)
	at com.squareup.moshi.JsonUtf8Reader.peek(JsonUtf8Reader.java:171)
	at com.squareup.moshi.JsonAdapter$2.fromJson(JsonAdapter.java:134)
	at com.squareup.moshi.JsonAdapter.fromJson(JsonAdapter.java:36)
	at org.kethereum.rpc.EthereumRPC.getBlockNumberString(EthereumRPC.kt:34)
@ligi
Copy link
Member

ligi commented Aug 8, 2018

Thanks for the feedback - but not sure if this would be a good approach as this is still not json then. lenient will not help much in this case as far as I see

@hshar7
Copy link
Author

hshar7 commented Aug 8, 2018

Any other idea on how to solve the issue? Most basic auth systems do not return json.

@ligi
Copy link
Member

ligi commented Aug 8, 2018

I think it should throw an exception - perhaps it should be a different exception though. Like NotAuthenticatedException.
So I think the solution would be to check if the code is != 200 -> and if it is unauthenticated -> throw this error

@ligi
Copy link
Member

ligi commented Aug 13, 2018

@hshar7 is your service exposed publicly by any chance? would love to test against the real problem ;-)

@hshar7
Copy link
Author

hshar7 commented Aug 15, 2018

@ligi Sure please do! It isn't exposed publicly but you can can your own instance at https://kaleido.io/
it's really easy to create one. Let me know if you have any questions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants