mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 19:13:31 +01:00
fix(rest): sublimit all requests on unhandled routes (#7366)
This commit is contained in:
@@ -166,7 +166,7 @@ nock(`${DefaultRestOptions.api}/v${DefaultRestOptions.version}`)
|
|||||||
];
|
];
|
||||||
})
|
})
|
||||||
.get('/unexpected')
|
.get('/unexpected')
|
||||||
.times(2)
|
.times(3)
|
||||||
.reply((): nock.ReplyFnResult => {
|
.reply((): nock.ReplyFnResult => {
|
||||||
if (unexpected429) {
|
if (unexpected429) {
|
||||||
unexpected429 = false;
|
unexpected429 = false;
|
||||||
@@ -310,9 +310,22 @@ test('Handle sublimits', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Handle unexpected 429', async () => {
|
test('Handle unexpected 429', async () => {
|
||||||
const previous = Date.now();
|
const previous = performance.now();
|
||||||
expect(await api.get('/unexpected')).toStrictEqual({ test: true });
|
let firstResolvedTime: number;
|
||||||
expect(Date.now()).toBeGreaterThanOrEqual(previous + 1000);
|
let secondResolvedTime: number;
|
||||||
|
const unexepectedSublimit = api.get('/unexpected').then((res) => {
|
||||||
|
firstResolvedTime = performance.now();
|
||||||
|
return res;
|
||||||
|
});
|
||||||
|
const queuedSublimit = api.get('/unexpected').then((res) => {
|
||||||
|
secondResolvedTime = performance.now();
|
||||||
|
return res;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(await unexepectedSublimit).toStrictEqual({ test: true });
|
||||||
|
expect(await queuedSublimit).toStrictEqual({ test: true });
|
||||||
|
expect(performance.now()).toBeGreaterThanOrEqual(previous + 1000);
|
||||||
|
expect(secondResolvedTime).toBeGreaterThan(firstResolvedTime);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Handle unexpected 429 cloudflare', async () => {
|
test('Handle unexpected 429 cloudflare', async () => {
|
||||||
|
|||||||
@@ -33,5 +33,6 @@ export function hasSublimit(bucketRoute: string, body?: unknown, method?: string
|
|||||||
return ['name', 'topic'].some((key) => Reflect.has(castedBody, key));
|
return ['name', 'topic'].some((key) => Reflect.has(castedBody, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
// If we are checking if a request has a sublimit on a route not checked above, sublimit all requests to avoid a flood of 429s
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user