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

Invalid JSON RPC 2.0 error responses #29

Closed
mfya opened this issue Apr 14, 2015 · 3 comments
Closed

Invalid JSON RPC 2.0 error responses #29

mfya opened this issue Apr 14, 2015 · 3 comments

Comments

@mfya
Copy link

mfya commented Apr 14, 2015

Some errors cause response objects that violate the JSON RPC 2.0 spec, because they have both, a "result" and "error" member set. An example would be MethodNotFoundError.

See https://github.com/cenobites/flask-jsonrpc/blob/723db17b1ef11d15d4180fd0e372b9a51723f4e4/flask_jsonrpc/site.py#L186-195 .
It seems that the version is initialized to late in the marked block and early exceptions are handled with the JSON RPC 1.0 spec, because the version_hint is always "1.0".

@nycholas
Copy link
Member

Hello,

By default the version is "1.0", in line[1] remove key "error" by response, and in lines[2][3][4][5]
remove key "result" by response if throw error.

Do you have any example with this problem?

Thank you.

[1] -

if version in ('1.1', '2.0') and 'error' in response and not response['error']:

[2] -
if version in ('1.1', '2.0') and 'error' in response:

[3] -
if version in ('1.1', '2.0') and 'result' in response:

[4] -
if version in ('1.1', '2.0') and 'result' in response:

[5] -
if version in ('1.1', '2.0') and 'result' in response:

@nycholas
Copy link
Member

Hello,

$ curl -i -X POST -d '{"jsonrpc": "2.0", "method": "App.methodNotFound", "params": {}, "id": "1"}' http://localhost:5000/api
HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 515
Server: Werkzeug/0.8.3 Python/2.7.9
Date: Thu, 16 Apr 2015 13:45:44 GMT

{
  "error": {
    "code": -32601, 
    "data": null, 
    "executable": "/usr/bin/python2", 
    "message": "MethodNotFoundError: Method not found. Available methods: App.index\nsystem.describe", 
    "name": "MethodNotFoundError", 
    "stack": "Traceback (most recent call last):\n  File \"/home/nycholas/project/src/o_lalertom/flask/flask-jsonrpc/flask_jsonrpc/site.py\", line 184, in response_dict\n    .format('\\n'.join(list(self.urls.keys()))))\nMethodNotFoundError\n"
  }, 
  "id": "1", 
  "result": null

Yes! It's a problem.

Thank you.

@nycholas
Copy link
Member

Fixed in version 0.3.

Thank you.

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

No branches or pull requests

2 participants