-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
Add error handler to unexpected exception #568
Conversation
Example: ``` app = Flask('minimal') jsonrpc = JSONRPC(app, '/api', enable_web_browsable_api=True) class MyException(Exception): pass @jsonrpc.errorhandler(MyException) def handle_my_exception(ex: MyException) -> t.Dict[str, t.Any]: return {'message': 'It is a custom exception', 'code': '0001'} @jsonrpc.method('App.failsWithCustomException') def fails_with_custom_exception(_string: t.Optional[str] = None) -> t.NoReturn: raise MyException('example of fail with custom exception that will be handled') ```` Note: The implementation does not support a global error handler, only a local one. In other words, the registration of an error handler will only be available for the JSON-RPC that has been registered. Resolve #375
github-actions-workflow-tests |
Running "Tests [Docker]" workflow. |
@nycholas But I wonder, can I re-throw that exception so that if |
@nycholas maybe we could retrun same excetion |
@Talkless Extends the error handler implementation to be able to control the HTTP headers and HTTPS status code it can be done, something like this. What the JSON-RPC specification disallowed is changing the struct of the response, it must be:
And, you can mix the |
I believe there's miscommunication of sorts. If we have endpoint like this:
And if That's why it seems it whould be usefull to not sink or to pass-through some exception to already-defined handlers. New
I dunno, so you say we should also respond in json-rcp-way even in low-level authentication error? |
I understood the use case, and what I mentioned, if the exception happens inside the JSON-RPC context, it needs to be a JSON-RPC exception, and I have suggested for that use case, the Flask handler errors can be used if you want to treat that the different way than JSON-RPC treat, besides that, I will allow that the JSON-RPC handler errors return the tuple of response, status_code, and headers to provide better integration with HTTP standards. Another suggestion is that you can use a custom JSON-RPC API, to do everything that you want with the response, look at the example:
And the tests:
So, the Flask handler error can be used to treat that exception. In other words, in your use case, the exception Does it make sense to you? Thank you. |
Yes, according to the specification, but if you see the answer above, I think that can solve your use case. |
Yes, thanks, but not sure I would want to re-implement I guess we'll just catch all |
Example:
Note: The implementation does not support a global error handler, only a local one. In other words, the registration of an error handler will only be available for the JSON-RPC that has been registered.
Resolve #375