Ensure rate limits are updated when requests fail
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Newtonsoft.Json;
|
||||
using Discord.Net.Rest;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
#if DEBUG_LIMITS
|
||||
@@ -54,9 +55,13 @@ namespace Discord.Net.Queue
|
||||
#if DEBUG_LIMITS
|
||||
Debug.WriteLine($"[{id}] Sending...");
|
||||
#endif
|
||||
TimeSpan lag = default(TimeSpan);
|
||||
RateLimitInfo info = default(RateLimitInfo);
|
||||
try
|
||||
{
|
||||
var response = await request.SendAsync().ConfigureAwait(false);
|
||||
TimeSpan lag = DateTimeOffset.UtcNow - DateTimeOffset.Parse(response.Headers["Date"]);
|
||||
var info = new RateLimitInfo(response.Headers);
|
||||
lag = DateTimeOffset.UtcNow - DateTimeOffset.Parse(response.Headers["Date"]);
|
||||
info = new RateLimitInfo(response.Headers);
|
||||
|
||||
if (response.StatusCode < (HttpStatusCode)200 || response.StatusCode >= (HttpStatusCode)300)
|
||||
{
|
||||
@@ -107,11 +112,22 @@ namespace Discord.Net.Queue
|
||||
#if DEBUG_LIMITS
|
||||
Debug.WriteLine($"[{id}] Success");
|
||||
#endif
|
||||
return response.Stream;
|
||||
}
|
||||
}
|
||||
#if DEBUG_LIMITS
|
||||
catch
|
||||
{
|
||||
Debug.WriteLine($"[{id}] Error");
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
finally
|
||||
{
|
||||
UpdateRateLimit(id, request, info, lag, false);
|
||||
#if DEBUG_LIMITS
|
||||
Debug.WriteLine($"[{id}] Stop");
|
||||
#endif
|
||||
return response.Stream;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user