-
-
Notifications
You must be signed in to change notification settings - Fork 891
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
Adds Class based namespaces error handling #834
Conversation
There are a couple of issues with your implementation:
What I would do to address the second problem is to handle namespace errors directly in the namespace class, without having to be registered. When |
Hey Miguel thanks for giving feedback so quickly, I will fix the first point! As for the second point, I don't think that I am understanding. From what I can tell, I think this would this have the similar affect without overriding the decorated handler for the namespace, but the one decorated handler would never be called? |
@codyleyhan here is an example that shows the problem: @socketio.on_error('/test')
def error_handler():
print('standalone error handler invoked'
@socketio.on('some_event', namespace='/test')
def some_event_handler(data):
raise RuntimeError("some_event error")
class MyCustomNamespace(Namespace):
def on_error(self):
print('namespace error handler invoked')
def on_another_event(self, data):
raise RuntimeError('another_event error')
socketio.on_namespace(MyCustomNamespace('/test')) With this example, if the client emits Now, if I were to move things around as follows: class MyCustomNamespace(Namespace):
def on_error(self):
print('namespace error handler invoked')
def on_another_event(self, data):
raise RuntimeError('another_event error')
socketio.on_namespace(MyCustomNamespace('/test'))
@socketio.on_error('/test')
def error_handler():
print('standalone error handler invoked'
@socketio.on('some_event', namespace='/test')
def some_event_handler(data):
raise RuntimeError("some_event error") Now the registered event handler is the decorated one, and it will be invoked even for the errors in the namespace handlers. In a large application that uses multiple modules, the order things get imported could determine where the error handler is. I want a more reliable solution that is deterministic, and independent of the order handlers are defined. What I think makes most sense is that the decorated error handler is used for decorated event handlers, and the namespace error handler is used for namespace event handlers. If the namespace does not have an error handler, then the decorated error handler should also be used for namespace events. I think a possible solution is to not register the namespace error handler with |
03a7df0
to
1fd43a3
Compare
Closing this due to inactivity. Please reopen or open a new PR with the changes I requested if you'd like to continue with this feature. |
Adds the ability to have an
on_error
handler on a class based namespace that will handle any errors within the namespace rather than having to register it separately.Addresses #832