Repository: discordjs/discord.js
File: packages/rest/src/lib/handlers/SequentialHandler.ts (TypeScript)

Code before:
				 * route-wide rate limit. Don't update remaining or reset to avoid rate limiting the whole
				 * endpoint, just set a reset time on the request itself to avoid retrying too soon.
				 */
				sublimitTimeout = retryAfter;
			}
		}

		// Count the invalid requests
		if (status === 401 || status === 403 || status === 429) {
			incrementInvalidCount(this.manager);
		}

		if (res.ok) {
			return res;
		} else if (status === 429) {
			// A rate limit was hit - this may happen if the route isn't associated with an official bucket hash yet, or when first globally rate limited
			const isGlobal = this.globalLimited;
			let limit: number;
			let timeout: number;

			if (isGlobal) {
				const offset = normalizeRateLimitOffset(this.manager.options.offset, routeId.bucketRoute);

				// Set RateLimitData based on the global limit
				limit = this.manager.options.globalRequestsPerSecond;
				timeout = offset - Date.now();
			} else {
				// Set RateLimitData based on the route-specific limit
				limit = this.limit;
				timeout = this.getTimeToReset(routeId);
			}

			await onRateLimit(this.manager, {
				global: isGlobal,
				method,
				url,
				route: routeId.bucketRoute,
				majorParameter: this.majorParameter,
				hash: this.hash,
				limit,
				timeToReset: timeout,
				retryAfter,
				sublimitTimeout: sublimitTimeout ?? 0,
				scope,
			});

			this.debug(
				[
					'Encountered unexpected 429 rate limit',
					`  Global         : ${isGlobal.toString()}`,
					`  Method         : ${method}`,

Review comment (suggestion):
```suggestion
				timeout = this.manager.globalReset + offset - Date.now();
```

Ditto

Code after:
				 * route-wide rate limit. Don't update remaining or reset to avoid rate limiting the whole
				 * endpoint, just set a reset time on the request itself to avoid retrying too soon.
				 */
				sublimitTimeout = retryAfter;
			}
		}

		// Count the invalid requests
		if (status === 401 || status === 403 || status === 429) {
			incrementInvalidCount(this.manager);
		}

		if (res.ok) {
			return res;
		} else if (status === 429) {
			// A rate limit was hit - this may happen if the route isn't associated with an official bucket hash yet, or when first globally rate limited
			const isGlobal = this.globalLimited;
			let limit: number;
			let timeout: number;

			if (isGlobal) {
				const offset = normalizeRateLimitOffset(this.manager.options.offset, routeId.bucketRoute);

				// Set RateLimitData based on the global limit
				limit = this.manager.options.globalRequestsPerSecond;
				timeout = this.manager.globalReset + offset - Date.now();
			} else {
				// Set RateLimitData based on the route-specific limit
				limit = this.limit;
				timeout = this.getTimeToReset(routeId);
			}

			await onRateLimit(this.manager, {
				global: isGlobal,
				method,
				url,
				route: routeId.bucketRoute,
				majorParameter: this.majorParameter,
				hash: this.hash,
				limit,
				timeToReset: timeout,
				retryAfter,
				sublimitTimeout: sublimitTimeout ?? 0,
				scope,
			});

			this.debug(
				[
					'Encountered unexpected 429 rate limit',
					`  Global         : ${isGlobal.toString()}`,
					`  Method         : ${method}`,