Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions Extension/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,10 +630,10 @@ export function downloadFileToDestination(urlStr: string, destinationPath: strin
// Write file using downloaded data
let createdFile: fs.WriteStream = fs.createWriteStream(destinationPath);
createdFile.on('finish', () => { resolve(); });
response.on('error', (error) => { reject(); });
response.on('error', (error) => { reject(error); });
response.pipe(createdFile);
});
request.on('error', (error) => { reject(); });
request.on('error', (error) => { reject(error); });
request.end();
});
}
Expand Down Expand Up @@ -663,10 +663,10 @@ export function downloadFileToStr(urlStr: string, headers?: OutgoingHttpHeaders)
}
let downloadedData: string = '';
response.on('data', (data) => { downloadedData += data; });
response.on('error', (error) => { reject(); });
response.on('error', (error) => { reject(error); });
response.on('end', () => { resolve(downloadedData); });
});
request.on('error', (error) => { reject(); });
request.on('error', (error) => { reject(error); });
request.end();
});
}
22 changes: 19 additions & 3 deletions Extension/src/githubAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,15 @@ function isRateLimit(input: any): input is RateLimit {
async function getRateLimit(): Promise<RateLimit> {
const header: OutgoingHttpHeaders = { 'User-Agent': 'vscode-cpptools' };
const data: string = await util.downloadFileToStr('https://api.github.com/rate_limit', header)
.catch(() => { throw new Error('Failed to download rate limit JSON'); });
.catch((error) => {
if (error.code && error.code !== "ENOENT") {
// Only throw if the user is connected to the Internet.
throw new Error('Failed to download rate limit JSON');
}
});
if (!data) {
return Promise.resolve(null);
}

let rateLimit: any;
try {
Expand All @@ -229,7 +237,7 @@ async function getRateLimit(): Promise<RateLimit> {

async function rateLimitExceeded(): Promise<boolean> {
const rateLimit: RateLimit = await getRateLimit();
return rateLimit.rate.remaining <= 0;
return rateLimit && rateLimit.rate.remaining <= 0;
}

/**
Expand All @@ -246,7 +254,15 @@ async function getReleaseJson(): Promise<Build[]> {
const header: OutgoingHttpHeaders = { 'User-Agent': 'vscode-cpptools' };

const data: string = await util.downloadFileToStr(releaseUrl, header)
.catch(() => { throw new Error('Failed to download release JSON'); });
.catch((error) => {
if (error.code && error.code !== "ENOENT") {
// Only throw if the user is connected to the Internet.
throw new Error('Failed to download release JSON');
}
});
if (!data) {
return Promise.resolve(null);
}

// Parse the file
let releaseJson: any;
Expand Down