Skip to content

Commit

Permalink
Merge pull request #23 from HighCommander4/vscode-issue-406
Browse files Browse the repository at this point in the history
Add timeout to github API request
  • Loading branch information
HighCommander4 committed Mar 2, 2023
2 parents 2ccb339 + a6c9216 commit 76ab333
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,19 @@ export interface Asset {

// Fetch the metadata for the latest stable clangd release.
export async function latestRelease(): Promise<Release> {
const response = await fetch(githubReleaseURL);
if (!response.ok) {
console.log(response.url, response.status, response.statusText);
throw new Error(`Can't fetch release: ${response.statusText}`);
const timeoutController = new AbortController();
const timeout = setTimeout(() => { timeoutController.abort(); }, 5000);
try {
const response =
await fetch(githubReleaseURL, {signal: timeoutController.signal});
if (!response.ok) {
console.log(response.url, response.status, response.statusText);
throw new Error(`Can't fetch release: ${response.statusText}`);
}
return await response.json() as Release;
} finally {
clearTimeout(timeout);
}
return await response.json() as Release;
}

// Determine which release asset should be installed for this machine.
Expand Down

0 comments on commit 76ab333

Please sign in to comment.