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 Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
#if DEBUG_LIMITS
|
#if DEBUG_LIMITS
|
||||||
@@ -54,9 +55,13 @@ namespace Discord.Net.Queue
|
|||||||
#if DEBUG_LIMITS
|
#if DEBUG_LIMITS
|
||||||
Debug.WriteLine($"[{id}] Sending...");
|
Debug.WriteLine($"[{id}] Sending...");
|
||||||
#endif
|
#endif
|
||||||
|
TimeSpan lag = default(TimeSpan);
|
||||||
|
RateLimitInfo info = default(RateLimitInfo);
|
||||||
|
try
|
||||||
|
{
|
||||||
var response = await request.SendAsync().ConfigureAwait(false);
|
var response = await request.SendAsync().ConfigureAwait(false);
|
||||||
TimeSpan lag = DateTimeOffset.UtcNow - DateTimeOffset.Parse(response.Headers["Date"]);
|
lag = DateTimeOffset.UtcNow - DateTimeOffset.Parse(response.Headers["Date"]);
|
||||||
var info = new RateLimitInfo(response.Headers);
|
info = new RateLimitInfo(response.Headers);
|
||||||
|
|
||||||
if (response.StatusCode < (HttpStatusCode)200 || response.StatusCode >= (HttpStatusCode)300)
|
if (response.StatusCode < (HttpStatusCode)200 || response.StatusCode >= (HttpStatusCode)300)
|
||||||
{
|
{
|
||||||
@@ -107,11 +112,22 @@ namespace Discord.Net.Queue
|
|||||||
#if DEBUG_LIMITS
|
#if DEBUG_LIMITS
|
||||||
Debug.WriteLine($"[{id}] Success");
|
Debug.WriteLine($"[{id}] Success");
|
||||||
#endif
|
#endif
|
||||||
|
return response.Stream;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#if DEBUG_LIMITS
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Debug.WriteLine($"[{id}] Error");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
finally
|
||||||
|
{
|
||||||
UpdateRateLimit(id, request, info, lag, false);
|
UpdateRateLimit(id, request, info, lag, false);
|
||||||
#if DEBUG_LIMITS
|
#if DEBUG_LIMITS
|
||||||
Debug.WriteLine($"[{id}] Stop");
|
Debug.WriteLine($"[{id}] Stop");
|
||||||
#endif
|
#endif
|
||||||
return response.Stream;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user