Improved handling of SSL/TLS error

This commit is contained in:
RogueException
2015-11-03 19:08:17 -04:00
parent 0eb0e14bba
commit 60610abe5d

View File

@@ -52,19 +52,15 @@ namespace Discord.Net.Rest
} }
private async Task<string> Send(RestRequest request, CancellationToken cancelToken) private async Task<string> Send(RestRequest request, CancellationToken cancelToken)
{ {
bool hasRetried = false; int retryCount = 0;
while (true) while (true)
{ {
var response = await _client.ExecuteTaskAsync(request, cancelToken).ConfigureAwait(false); var response = await _client.ExecuteTaskAsync(request, cancelToken).ConfigureAwait(false);
int statusCode = (int)response.StatusCode; int statusCode = (int)response.StatusCode;
if (statusCode == 0) //Internal Error if (statusCode == 0) //Internal Error
{ {
if (!hasRetried) if (response.ErrorException.HResult == -2146233079 && retryCount++ < 5) //The request was aborted: Could not create SSL/TLS secure channel.
{ continue; //Seems to work if we immediately retry
//SSL/TTS Error seems to work if we immediately retry
hasRetried = true;
continue;
}
throw response.ErrorException; throw response.ErrorException;
} }
if (statusCode < 200 || statusCode >= 300) //2xx = Success if (statusCode < 200 || statusCode >= 300) //2xx = Success