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

Code before:
	url: string,
	requestData: HandlerRequestData,
	retries: number,
) {
	const status = res.status;
	if (status >= 500 && status < 600) {
		// Retry the specified number of times for possible server side issues
		if (retries !== manager.options.retries) {
			return null;
		}

		// We are out of retries, throw an error
		throw new HTTPError(status, res.statusText, method, url, requestData);
	} else {
		// Handle possible malformed requests
		if (status >= 400 && status < 500) {
			// The request will not succeed for some reason, parse the error returned from the api
			const data = (await parseResponse(res)) as DiscordErrorData | OAuthErrorData;
			const isDiscordError = 'code' in data;

			// If we receive this status code, it means the token we had is no longer valid.
			if (status === 401 && requestData.auth === true) {
				if (isDiscordError && data.code !== 0 && !authFalseWarningEmitted) {
					const errorText = `Encountered HTTP 401 with error ${data.code}: ${data.message}. Your token will be removed from this REST instance. If you are using @discordjs/rest directly, consider adding 'auth: false' to the request. Open an issue with your library if not.`;
					// Use emitWarning if possible, probably not available in edge / web
					if (typeof process?.emitWarning === 'function') {
						process.emitWarning(errorText);
					} else {
						console.warn(errorText);
					}

					authFalseWarningEmitted = true;
				}

				manager.setToken(null!);
			}

			// throw the API error
			throw new DiscordAPIError(data, isDiscordError ? data.code : data.error, status, method, url, requestData);
		}

		return res;
	}
}


Review comment (suggestion):
Seems more likely that `process` wouldn't be declared at all rather than being nullish

```suggestion
					if (typeof process !== 'undefined' && typeof process.emitWarning === 'function') {
```

Code after:
	url: string,
	requestData: HandlerRequestData,
	retries: number,
) {
	const status = res.status;
	if (status >= 500 && status < 600) {
		// Retry the specified number of times for possible server side issues
		if (retries !== manager.options.retries) {
			return null;
		}

		// We are out of retries, throw an error
		throw new HTTPError(status, res.statusText, method, url, requestData);
	} else {
		// Handle possible malformed requests
		if (status >= 400 && status < 500) {
			// The request will not succeed for some reason, parse the error returned from the api
			const data = (await parseResponse(res)) as DiscordErrorData | OAuthErrorData;
			const isDiscordError = 'code' in data;

			// If we receive this status code, it means the token we had is no longer valid.
			if (status === 401 && requestData.auth === true) {
				if (isDiscordError && data.code !== 0 && !authFalseWarningEmitted) {
					const errorText = `Encountered HTTP 401 with error ${data.code}: ${data.message}. Your token will be removed from this REST instance. If you are using @discordjs/rest directly, consider adding 'auth: false' to the request. Open an issue with your library if not.`;
					// Use emitWarning if possible, probably not available in edge / web
					if (typeof globalThis.process !== 'undefined' && typeof globalThis.process.emitWarning === 'function') {
						globalThis.process.emitWarning(errorText);
					} else {
						console.warn(errorText);
					}

					authFalseWarningEmitted = true;
				}

				manager.setToken(null!);
			}

			// throw the API error
			throw new DiscordAPIError(data, isDiscordError ? data.code : data.error, status, method, url, requestData);
		}

		return res;
	}
}