pavlov99 / json-rpc

🔁 JSON-RPC 1/2 transport implementation. Supports python 2/3 and pypy.
http://json-rpc.readthedocs.org
MIT License
464 stars 101 forks source link

JSONRPCResponseManager.handle silences the exception if "id" is not passed #124

Open faerot opened 2 years ago

faerot commented 2 years ago

Description

There is no way to handle exceptions if request does not pass "id" attribute. JSONRPCResponseManager.handle() should always return a response with an error in case of exception in user code or if it is not possible, there should be an argument to enable this (strict) behavior.

Steps to Reproduce

Run this code:

import jsonrpc

dispatcher = jsonrpc.Dispatcher()

@dispatcher.add_method
def test():
    1/0

request = '{"jsonrpc": "2.0", "method": "test", "params": []}'

print(jsonrpc.JSONRPCResponseManager.handle(request, dispatcher))

Expected behavior: error response should be printed

Actual behavior: None is printed

Reproduces how often: always

Versions

all

Additional Information

If you change request to '{"jsonrpc": "2.0", "method": "test", "params": [], "id": 1}' it expectedly returns response with an error:

{'jsonrpc': '2.0', 'id': 1, 'error': {'message': 'Server error', 'code': -32000, 'data': {'message': 'integer division or modulo by zero', 'args': ('integer division or modulo by zero',), 'type': 'ZeroDivisionError'}}}