about summary refs log tree commit diff
path: root/LibMatrix/Extensions/HttpClientExtensions.cs
diff options
context:
space:
mode:
Diffstat (limited to 'LibMatrix/Extensions/HttpClientExtensions.cs')
-rw-r--r--LibMatrix/Extensions/HttpClientExtensions.cs16
1 files changed, 13 insertions, 3 deletions
diff --git a/LibMatrix/Extensions/HttpClientExtensions.cs b/LibMatrix/Extensions/HttpClientExtensions.cs
index 5bb0dc2..913864e 100644
--- a/LibMatrix/Extensions/HttpClientExtensions.cs
+++ b/LibMatrix/Extensions/HttpClientExtensions.cs
@@ -53,11 +53,21 @@ public class MatrixHttpClient : HttpClient {
             Console.WriteLine(e);
         }
 
-        var a = await base.SendAsync(request, cancellationToken);
-        if (a.IsSuccessStatusCode) return a;
+        HttpResponseMessage responseMessage;
+        try {
+            responseMessage = await base.SendAsync(request, cancellationToken);
+        }
+        catch (Exception e) {
+            typeof(HttpRequestMessage).GetField("_sendStatus", BindingFlags.NonPublic | BindingFlags.Instance)
+                ?.SetValue(request, 0);
+            await Task.Delay(2500);
+            return await SendAsync(request, cancellationToken);
+        }
+
+        if (responseMessage.IsSuccessStatusCode) return responseMessage;
 
         //error handling
-        var content = await a.Content.ReadAsStringAsync(cancellationToken);
+        var content = await responseMessage.Content.ReadAsStringAsync(cancellationToken);
         if (content.Length == 0)
             throw new MatrixException() {
                 ErrorCode = "M_UNKNOWN",