How to see WS bad handshake error status code?

Hi!
When the number of connections to the websocket increases, an websocket: bad handshake error starts to come in response. Changing the number of websocket instances helps solve this problem, but I would still like to know more. Maybe there is some way to get not only a generalized error, but also a status code?

I can’t easily reproduce this, but the connect() function in k6/ws returns an http.Response object that should have these details. Additionally, the error event might have some details if the error occurred after the initial connection was established.

The problem is that the response in the cases I described is always undefined. The connection just doesn’t work and the error event can’t be received either.
Now the only way is to fork the websocket library and try to work with it, but I was hoping that there was still an easier way.

I think that you are hitting WebSocket connection does not respect the `throw` option · Issue #2247 · grafana/k6 · GitHub which hasn’t been picked up by anyone.

Additionally, due to the fact that the ws API isn’t great we will likely prioritize xk6 extensions experiment: websocket API · Issue #2425 · grafana/k6 · GitHub (which I am actually working on now) and try to get something in that vein in core and deprecate the current API. This though won’t happen this release cycle and might not be possible to be finished in the next one as well. So if you want you are welcome to work on the above issue.