-
Notifications
You must be signed in to change notification settings - Fork 78
[ETCM-448] json rpc - status code #836
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
Conversation
lemastero
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
src/main/scala/io/iohk/ethereum/jsonrpc/server/http/JsonRpcHttpServer.scala
Show resolved
Hide resolved
|
Please update the description of the issue :) |
|
@conqeror Please verify it's working with wallet in case of errors (it should) |
|
Yes @kapke, the node and faucet using the same class, both have the same behavior. So, with this, we need to change faucet ui and wallet ui. |
enriquerodbe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, only comments for readability
| private def handleResponse(f: Task[JsonRpcResponse]): Task[(StatusCode, JsonRpcResponse)] = f map { jsonRpcResponse => | ||
| jsonRpcResponse.error match { | ||
| case Some(JsonRpcError(error, _, _)) | ||
| if List(JsonRpcError.InvalidRequest.code, JsonRpcError.ParseError.code, JsonRpcError.InvalidParams().code) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For readability, this List of errors could be extracted to a constant at the class level or companion object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
|
||
| postRequest ~> Route.seal(mockJsonRpcHttpServer.route) ~> check { | ||
| status shouldEqual StatusCodes.OK | ||
| responseAs[String] shouldEqual |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think if instead of comparing Strings (which in case of an error forces the developer to compare the whole string to find the difference), we parse the response as Json and assert each attribute individually?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
@biandratti I meant - if faucet's rpc client handles errors from mantis node properly? IIRC faucet is being run as a separate process communicating with Mantis over RPC. |
|
@kapke @biandratti Regarding mantis wallet - let me know when this gets merged and I will test it. I don't expect that it will require immediate changes, but it should enable us to handle errors more easily (...no more Internal JSON-RPC error everywhere :) |
Good question @kapke
|
kapke
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
lemastero
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 Nice work.
Description
Today for every error in json rpc we return status code 200.
As per the 2.0 spec, there is no reason for using anything but 200 http status code whenever we are doing JSON-RPC over HTTP.
Also, returning 400 for valid JSON-RPC requests doesn't help when integrating with JSON-RPC clients.
Proposed Solution
Any valid JSON-RPC request should generate a JSON-RPC response, the HTTP status code should be 200. No matter if the response is a success or error response.
Calling a method that hasn't been enabled or a method that doesn't exist are valid JSON-RPC requests, therefore the expected response is a JSON-RPC error and the status code 200.
Any invalid JSON-RPC request (malformed json, etc) should generate a 400 status code.
So in this way we have status code 400 for json rpc error: [-32600, -32602, -32700]. In other cases we have status code 200.
Important Changes Introduced
Possibly requires change of integration with faucet ui and wallet.