about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-07-31 13:25:42 +0200
committerRory& <root@rory.gay>2025-07-31 13:25:42 +0200
commit96daf84ffb1a32e376a616d9ffa2fd6412f5fbfa (patch)
tree3cb9f9c1553fa05d945ffcf94467f1260dd115d5
parentSync ArcaneLibs (diff)
downloadLibMatrix-96daf84ffb1a32e376a616d9ffa2fd6412f5fbfa.tar.xz
Follow retry-after or fall back to 500ms on ratelimit exceeded errors
Diffstat (limited to '')
-rw-r--r--LibMatrix/Extensions/MatrixHttpClient.Single.cs13
1 files changed, 8 insertions, 5 deletions
diff --git a/LibMatrix/Extensions/MatrixHttpClient.Single.cs b/LibMatrix/Extensions/MatrixHttpClient.Single.cs

index d14e481..430a6e5 100644 --- a/LibMatrix/Extensions/MatrixHttpClient.Single.cs +++ b/LibMatrix/Extensions/MatrixHttpClient.Single.cs
@@ -184,11 +184,14 @@ public class MatrixHttpClient { Debug.Assert(ex != null, nameof(ex) + " != null"); ex.RawContent = content; // Console.WriteLine($"Failed to send request: {ex}"); - if (ex.RetryAfterMs is null) throw ex!; - //we have a ratelimit error - await Task.Delay(ex.RetryAfterMs.Value, cancellationToken); - request.ResetSendStatus(); - return await SendAsync(request, cancellationToken); + if (ex.ErrorCode == MatrixException.ErrorCodes.M_LIMIT_EXCEEDED) { + // if (ex.RetryAfterMs is null) throw ex!; + //we have a ratelimit error + await Task.Delay(ex.RetryAfterMs ?? responseMessage.Headers.RetryAfter?.Delta?.Milliseconds ?? 500, cancellationToken); + request.ResetSendStatus(); + return await SendAsync(request, cancellationToken); + } + throw ex; } if (responseMessage.StatusCode == HttpStatusCode.BadGateway) {