Make rate limit parser more resilient
This commit is contained in:
parent
ef9b69a997
commit
18cf863834
@ -13,22 +13,27 @@ namespace Myriad.Rest.Ratelimit
|
||||
ServerDate = response.Headers.Date;
|
||||
|
||||
if (response.Headers.TryGetValues("X-RateLimit-Limit", out var limit))
|
||||
Limit = int.Parse(limit!.First());
|
||||
if (int.TryParse(limit.First(), out var limitNum))
|
||||
Limit = limitNum;
|
||||
|
||||
if (response.Headers.TryGetValues("X-RateLimit-Remaining", out var remaining))
|
||||
Remaining = int.Parse(remaining!.First());
|
||||
if (int.TryParse(remaining!.First(), out var remainingNum))
|
||||
Remaining = remainingNum;
|
||||
|
||||
if (response.Headers.TryGetValues("X-RateLimit-Reset", out var reset))
|
||||
Reset = DateTimeOffset.FromUnixTimeMilliseconds((long) (double.Parse(reset!.First()) * 1000));
|
||||
if (double.TryParse(reset!.First(), out var resetNum))
|
||||
Reset = DateTimeOffset.FromUnixTimeMilliseconds((long) (resetNum * 1000));
|
||||
|
||||
if (response.Headers.TryGetValues("X-RateLimit-Reset-After", out var resetAfter))
|
||||
ResetAfter = TimeSpan.FromSeconds(double.Parse(resetAfter!.First()));
|
||||
if (double.TryParse(resetAfter!.First(), out var resetAfterNum))
|
||||
ResetAfter = TimeSpan.FromSeconds(resetAfterNum);
|
||||
|
||||
if (response.Headers.TryGetValues("X-RateLimit-Bucket", out var bucket))
|
||||
Bucket = bucket.First();
|
||||
|
||||
if (response.Headers.TryGetValues("X-RateLimit-Global", out var global))
|
||||
Global = bool.Parse(global!.First());
|
||||
if (bool.TryParse(global!.First(), out var globalBool))
|
||||
Global = globalBool;
|
||||
}
|
||||
|
||||
public bool Global { get; init; }
|
||||
|
Loading…
Reference in New Issue
Block a user