Skip to content

fix: Improve GitHub API rate limit handling with PAT support #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/serverDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,24 @@ export class ServerDownloader {
) {}

private async latestReleaseInfo(): Promise<GitHubReleasesAPIResponse> {
const rawJson = await requestPromise.get(`https://api.github.com/repos/fwcd/${this.githubProjectName}/releases/latest`, {
headers: { "User-Agent": "vscode-kotlin-ide" }
});
return JSON.parse(rawJson) as GitHubReleasesAPIResponse;
const headers: { [key: string]: string } = {
"User-Agent": "vscode-kotlin-ide"
};

const token = process.env.GITHUB_TOKEN;
if (token) {
headers["Authorization"] = `Bearer ${token}`;
}

try {
const rawJson = await requestPromise.get(`https://api.github.com/repos/fwcd/${this.githubProjectName}/releases/latest`, { headers });
return JSON.parse(rawJson) as GitHubReleasesAPIResponse;
} catch (error) {
if (error.statusCode === 403 && !token) {
LOG.warn("GitHub API rate limit exceeded. Consider setting GITHUB_TOKEN environment variable to increase the rate limit.");
}
throw error;
}
}

private serverInfoFile(): string {
Expand Down