-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Retrieving HTTP response body on failures #1872
Comments
What is the point of using the default behavior if you are handling the "unexpected" response yourself? When you are done reading the HTTP response body you can do whatever you want. For example you could emit a custom event that gives you the response status code and body and then eventually call I'm not happy with exposing I'm also not happy with a middleware API because I think it is not needed for something as simple as this. |
Thanks for pointing to the discussion about this issue. I see your point and see that you understood my request, so I'll not try to re-argue the same things. So I'll go on with another question: If it is mandatory, please consider adding a note to the documentation of how the socket should be closed after handling the event. |
It depends:
|
@lpinca, thank you very much for your help and time. This really helped. |
Description
This is a feature request for an easy way to retrieve the HTTP response body in case of HTTP failures while establishing the WebSocket.
Currently, the
error
event that is raised in this case only includes the status code.By using the
unexpected-response
event which is intended for such cases, the default behavior of handling the failure is not executed.My request is to have something similar to
unexpected-response
with a way to execute the default failure handling.The motivation for this request is that some services (e.g., Azure Speech-To-Text) reply with 400 response in some cases, having the exact error specified in the body of the response. We are searching for a way to debug those cases.
Reproducible in:
Workaround code
As a workaround (and to show what I'm missing), I created a wrapping class to the WebSocket that performs the action I need (see it working on replit):
With a small test function:
Some notes:
abortHandshake
function (that is copied from the lib) must only be called after the body is retrieved. Otherwise, the stream will be closed, and the body will not be accessible.Feature request:
I thought of two ways to make this easier to implement:
abortHandshake
function, so the implementation will be at the client responsibility (like done with my wrapper class), but giving him/her a way to execute the default behavior (removing the need to copy the internal function).I would love to hear your opinion on this.
Thanks,
Yehoshua
cc @orgads
The text was updated successfully, but these errors were encountered: