mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 00:40:07 +00:00
fix: 429 handling bug
This commit is contained in:
@@ -66,6 +66,9 @@ export async function processGlobalQueue(rest: RestManager) {
|
||||
bucketId: request.payload.bucketId,
|
||||
reject: request.request.reject,
|
||||
respond: request.request.respond,
|
||||
retryRequest: function() {
|
||||
rest.globalQueue.unshift(request);
|
||||
},
|
||||
retryCount: request.payload.retryCount ?? 0,
|
||||
payload: rest.createRequestBody(rest, {
|
||||
method: request.request.method,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { delay } from "../mod.ts";
|
||||
import { HTTPResponseCodes } from "../types/shared.ts";
|
||||
import { BASE_URL } from "../util/constants.ts";
|
||||
import { RequestMethod } from "./rest.ts";
|
||||
@@ -9,6 +10,7 @@ export interface RestSendRequestOptions {
|
||||
bucketId?: string;
|
||||
reject?: Function;
|
||||
respond?: Function;
|
||||
retryRequest?: Function;
|
||||
retryCount?: number;
|
||||
payload?: {
|
||||
headers: Record<string, string>;
|
||||
@@ -94,6 +96,7 @@ export async function sendRequest<T>(rest: RestManager, options: RestSendRequest
|
||||
body,
|
||||
});
|
||||
} else {
|
||||
// TOO MANY ATTEMPTS, GET RID OF REQUEST FROM QUEUE.
|
||||
if (options.retryCount && options.retryCount++ >= rest.maxRetryCount) {
|
||||
rest.debug(`[REST - RetriesMaxed] ${JSON.stringify(options)}`);
|
||||
// REMOVE ITEM FROM QUEUE TO PREVENT RETRY
|
||||
@@ -105,6 +108,11 @@ export async function sendRequest<T>(rest: RestManager, options: RestSendRequest
|
||||
|
||||
// @ts-ignore Code should never reach here
|
||||
return;
|
||||
} // RATE LIMITED, ADD BACK TO QUEUE
|
||||
else {
|
||||
const json = await response.json();
|
||||
await delay(json.retry_after * 1000);
|
||||
return options.retryRequest?.();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user