mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Adds extra error information from response to bad handshake error when possible
This commit is contained in:
parent
d21b17264e
commit
f387f0b69a
@ -111,6 +111,10 @@ func (rt *RoundTripper) RoundTrip(request *http.Request) (retResp *http.Response
|
||||
wsConn, resp, err := dialer.DialContext(request.Context(), request.URL.String(), request.Header)
|
||||
if err != nil {
|
||||
if errors.Is(err, gwebsocket.ErrBadHandshake) {
|
||||
// Enhance the error message with the response status if possible.
|
||||
if resp != nil && len(resp.Status) > 0 {
|
||||
err = fmt.Errorf("%w (%s)", err, resp.Status)
|
||||
}
|
||||
return nil, &httpstream.UpgradeFailureError{Cause: err}
|
||||
}
|
||||
return nil, err
|
||||
|
@ -87,7 +87,8 @@ func TestWebSocketRoundTripper_RoundTripperFails(t *testing.T) {
|
||||
_, err = rt.RoundTrip(req)
|
||||
// Ensure a "bad handshake" error is returned, since requested protocol is not supported.
|
||||
require.Error(t, err)
|
||||
assert.True(t, strings.Contains(err.Error(), "bad handshake"))
|
||||
assert.True(t, strings.Contains(err.Error(), "websocket: bad handshake"))
|
||||
assert.True(t, strings.Contains(err.Error(), "403 Forbidden"))
|
||||
assert.True(t, httpstream.IsUpgradeFailure(err))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user