I have a requirement to preserve the original response body in exceptions raised when websocket handshaking fails.
Currently there is no way to keep the original response body (and the reason string in the status line) along with the ClientResponseError objects.
Since reading the body is asynchronous while exceptions must be created at once and forgotten after raised, I think just hanging the body stream or the response object itself directly to exceptions would not be safe in terms of resource lifecycles. (related code)
An alternative to avoid such potential issues is to pre-read all of the body stream when raising ClientResponseError, but this assumes that the errorneous responses are “reasonably” small enough.
What could be done in this case? What’s your thoughts?