sanic-org / sanic

Accelerate your web app development | Build fast. Run fast.

Home Page:https://sanic.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error handler for websocket requests

jrayu opened this issue · comments

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe.

I am planning to redirect all error messages to an error collection platform. I see we are able to add error handlers to acheive this, but at websocket apis the error handler is not working. I read through the code, found out that while awaiting for response in app.py:968, the websocket handler itself took care of the exceptions already at app.py:1048 so the error is never handled at handle_request method.

Describe the solution you'd like

Is it possible to have an error handler for websocket like normal requests?

Additional context

No response

Just so you know I added a "raise" at app.py:1050 and the error handler is functioning properly. I am not sure what bug it might bring to the whole project though.

Could you provide a snippet of what you are looking at?

Error handlers are meant to generate HTTP responses. They would not really have an impact upon websockets since that operate on its own protocol. Running the handler would not be helpful because an exception in a ws handler is already past the point that an HTTP response makes sense. Perhaps I am misunderstanding the use case?