-
Notifications
You must be signed in to change notification settings - Fork 53
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
JSONRPCMethodNotFoundError and others doesn't allow to set unique ID #68
Comments
Hi, thanks for your report. JSONRPCRequest.error_respond() will copy the id from the request into the error response. If this doesn't help please provide more information, a code sample and/or pytest code demonstrating the problem. Note that the specification is ambivalent in the case of error responses and notifications. |
@lnoor, but |
@lnoor, here is a code snippet that represents my problem: class Handler:
"""HTTP handler for some abstract hypothetical web-framework"""
METHODS = {'method1', 'method2'}
def __init__(self):
self.__rpc = tinyrpc.protocols.jsonrpc.JSONRPCProtocol()
def handle(self, http_request):
"""Handle HTTP request."""
try:
request = self.__rpc.parse_request(http_request.body)
except tinyrpc.exc.BadRequestError as exc:
response = exc.error_respond()
return HTTPResonse(400, response.serialize())
if request.method not in METHODS:
# How do I construct a proper JSONRPC response here that would include a response ID? |
Warning: not tested code (just a pointer to get you going).
Provided in your own code you raise exception derived from FixedErrorMessageMixin (see docs about creating your own exceptions) this should deal with all errors. As a side note you may want to use HTTP response code 200 since you did return a valid reply and reserve the 40x codes for real HTTP statusses like "403 authorization required" etc. Do let me know if this works for you as I'm holding off on the release of 1.0 to have this issue fixed. |
@lnoor, in your example how exactly the unique ID is set in the response? JSON RPC spec requires it (at least in my interpretation). |
Yes the spec requires it.
|
@lnoor, it seems like I overlooked existence of |
I marked it for improved documentation so I keep it open for a while. |
Specification says that when error is returned, ID must be set when it's possible to recover it:
https://www.jsonrpc.org/specification
But such exceptions as
JSONRPCMethodNotFoundError
orJSONRPCInvalidParamsError
do not allow setting the ID. I encountered this problem when usingJSONRPCProtocol
class separately without other layers provided by the library.The text was updated successfully, but these errors were encountered: