mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 19:13:31 +01:00
fix(handlers): create burst handler for interaction callbacks (#8996)
* fix(handlers): create burst handler for interaction callbacks * docs: use remarks instead of info block Co-Authored-By: Almeida <almeidx@pm.me> * refactor: move code duplication to shared handler Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> * Update packages/rest/src/lib/handlers/BurstHandler.ts --------- Co-authored-by: Almeida <almeidx@pm.me> Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com> Co-authored-by: Aura Román <kyradiscord@gmail.com>
This commit is contained in:
@@ -55,3 +55,5 @@ export const OverwrittenMimeTypes = {
|
||||
// https://github.com/discordjs/discord.js/issues/8557
|
||||
'image/apng': 'image/png',
|
||||
} as const satisfies Readonly<Record<string, string>>;
|
||||
|
||||
export const BurstHandlerMajorIdKey = 'burst';
|
||||
|
||||
@@ -3,8 +3,9 @@ import { URLSearchParams } from 'node:url';
|
||||
import { types } from 'node:util';
|
||||
import type { RESTPatchAPIChannelJSONBody } from 'discord-api-types/v10';
|
||||
import { FormData, type Dispatcher, type RequestInit } from 'undici';
|
||||
import type { RequestOptions } from '../REST.js';
|
||||
import { RequestMethod } from '../RequestManager.js';
|
||||
import type { RateLimitData, RequestOptions } from '../REST.js';
|
||||
import { type RequestManager, RequestMethod } from '../RequestManager.js';
|
||||
import { RateLimitError } from '../errors/RateLimitError.js';
|
||||
|
||||
export function parseHeader(header: string[] | string | undefined): string | undefined {
|
||||
if (header === undefined || typeof header === 'string') {
|
||||
@@ -148,3 +149,21 @@ export function shouldRetry(error: Error | NodeJS.ErrnoException) {
|
||||
// Downlevel ECONNRESET to retry as it may be recoverable
|
||||
return ('code' in error && error.code === 'ECONNRESET') || error.message.includes('ECONNRESET');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the request should be queued or whether a RateLimitError should be thrown
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export async function onRateLimit(manager: RequestManager, rateLimitData: RateLimitData) {
|
||||
const { options } = manager;
|
||||
if (!options.rejectOnRateLimit) return;
|
||||
|
||||
const shouldThrow =
|
||||
typeof options.rejectOnRateLimit === 'function'
|
||||
? await options.rejectOnRateLimit(rateLimitData)
|
||||
: options.rejectOnRateLimit.some((route) => rateLimitData.route.startsWith(route.toLowerCase()));
|
||||
if (shouldThrow) {
|
||||
throw new RateLimitError(rateLimitData);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user