Skip to content

Commit 0a8db04

Browse files
committed
Add more error details when failing to upgrade a connection
1 parent 36d3318 commit 0a8db04

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/KubernetesClient/KubernetesRequest.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,9 @@ public async Task<ValueTuple<SPDYConnection, HttpResponseHeaders>> OpenSPDYAsync
353353
HttpResponseMessage respMsg = await client.SendAsync(reqMsg, HttpCompletionOption.ResponseHeadersRead, cancelToken).ConfigureAwait(false);
354354
if (respMsg.StatusCode != HttpStatusCode.SwitchingProtocols)
355355
{
356-
throw new HttpRequestException(
357-
"Unable to upgrade to SPDY/3.1 connection. " + await respMsg.Content.ReadAsStringAsync().ConfigureAwait(false));
356+
throw new KubernetesException(new V1Status() {
357+
Status = "Failure", Code = (int)respMsg.StatusCode, Reason = respMsg.StatusCode.ToString(),
358+
Message = "Unable to upgrade to SPDY/3.1 connection. " + await respMsg.Content.ReadAsStringAsync().ConfigureAwait(false) });
358359
}
359360

360361
Stream stream = await respMsg.Content.ReadAsStreamAsync().ConfigureAwait(false);
@@ -375,8 +376,9 @@ public async Task<ValueTuple<WebSocket, HttpResponseHeaders>> OpenWebSocketAsync
375376
HttpResponseMessage respMsg = await client.SendAsync(reqMsg, HttpCompletionOption.ResponseHeadersRead, cancelToken).ConfigureAwait(false);
376377
if(respMsg.StatusCode != HttpStatusCode.SwitchingProtocols)
377378
{
378-
throw new HttpRequestException(
379-
"Unable to upgrade to web socket connection. " + await respMsg.Content.ReadAsStringAsync().ConfigureAwait(false));
379+
throw new KubernetesException(new V1Status() {
380+
Status = "Failure", Code = (int)respMsg.StatusCode, Reason = respMsg.StatusCode.ToString(),
381+
Message = "Unable to upgrade to web socket connection. " + await respMsg.Content.ReadAsStringAsync().ConfigureAwait(false) });
380382
}
381383
Stream stream = await respMsg.Content.ReadAsStreamAsync().ConfigureAwait(false);
382384
return (WebSocket.CreateFromStream(stream, false, subprotocol, WebSocket.DefaultKeepAliveInterval), respMsg.Headers);

0 commit comments

Comments
 (0)