diff --git a/packages/rest/src/lib/handlers/SequentialHandler.ts b/packages/rest/src/lib/handlers/SequentialHandler.ts index c28ec445d298..4f5e5ccde7b8 100644 --- a/packages/rest/src/lib/handlers/SequentialHandler.ts +++ b/packages/rest/src/lib/handlers/SequentialHandler.ts @@ -8,7 +8,7 @@ import { DiscordAPIError, type DiscordErrorData, type OAuthErrorData } from '../ import { HTTPError } from '../errors/HTTPError.js'; import { RateLimitError } from '../errors/RateLimitError.js'; import { RESTEvents } from '../utils/constants.js'; -import { hasSublimit, parseHeader, parseResponse } from '../utils/utils.js'; +import { hasSublimit, parseHeader, parseResponse, shouldRetry } from '../utils/utils.js'; import type { IHandler } from './IHandler.js'; /** @@ -307,8 +307,9 @@ export class SequentialHandler implements IHandler { try { res = await request(url, { ...options, signal: controller.signal }); } catch (error: unknown) { - // Retry the specified number of times for possible timed out requests - if (error instanceof Error && error.name === 'AbortError' && retries !== this.manager.options.retries) { + if (!(error instanceof Error)) throw error; + // Retry the specified number of times if needed + if (shouldRetry(error) && retries !== this.manager.options.retries) { // eslint-disable-next-line no-param-reassign return await this.runRequest(routeId, url, options, requestData, ++retries); } diff --git a/packages/rest/src/lib/utils/utils.ts b/packages/rest/src/lib/utils/utils.ts index 770cc59c5168..6034fdaa5a41 100644 --- a/packages/rest/src/lib/utils/utils.ts +++ b/packages/rest/src/lib/utils/utils.ts @@ -135,3 +135,16 @@ export async function resolveBody(body: RequestInit['body']): Promise