Skip to content

Commit

Permalink
Better handle WebExceptions that don't have a Response and send a cus…
Browse files Browse the repository at this point in the history
…tomized exception on WebExceptionStatus.SendFailure errors (usually from TLS errors).

Fixes opentok#108.
  • Loading branch information
ATLCTO committed Oct 6, 2018
1 parent f9907ea commit 822613c
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions OpenTok/Util/HttpClient.cs
Expand Up @@ -116,17 +116,24 @@ public virtual string Delete(string url, Dictionary<string, string> headers, Dic

response = (HttpWebResponse)e.Response;

DebugLog("Response Status Code: " + response.StatusCode);
DebugLog("Response Status Description: " + response.StatusDescription);
DebugLogHeaders(response.Headers, "Response");

if (this.debug)
if (response != null)
{
using (var stream = new StreamReader(response.GetResponseStream()))
DebugLog("Response Status Code: " + response.StatusCode);
DebugLog("Response Status Description: " + response.StatusDescription);
DebugLogHeaders(response.Headers, "Response");

if (this.debug)
{
DebugLog("Response Body: " + stream.ReadToEnd());
using (var stream = new StreamReader(response.GetResponseStream()))
{
DebugLog("Response Body: " + stream.ReadToEnd());
}
}
}
else if (e.Status == WebExceptionStatus.SendFailure)
{
throw new OpenTokWebException("Error with request submission (TLS1.1 or other network/protocol issue)", e);

This comment has been minimized.

Copy link
@fidergo-stephane-gourichon

fidergo-stephane-gourichon May 3, 2019

This implements the "Handle send failures errors and throw exception with meaningful message" part but not the "
Include recommendation regarding TLS upgrade into exception message" part. Perhaps add this string: "Consider adding System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; before creating a session."

This comment has been minimized.

Copy link
@fidergo-stephane-gourichon
}

throw new OpenTokWebException("Error with request submission", e);
}
Expand Down

0 comments on commit 822613c

Please sign in to comment.