Handle download HTTP error (#511)

This commit is contained in:
Sergey Dolin 2022-10-24 11:10:18 +02:00 committed by GitHub
parent 8bcd2560e2
commit 4818a5a153
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 142 additions and 67 deletions

38
dist/setup/index.js vendored
View File

@ -66511,6 +66511,7 @@ function installPyPy(pypyVersion, pythonVersion, architecture, releases) {
const { foundAsset, resolvedPythonVersion, resolvedPyPyVersion } = releaseData;
let downloadUrl = `${foundAsset.download_url}`;
core.info(`Downloading PyPy from "${downloadUrl}" ...`);
try {
const pypyPath = yield tc.downloadTool(downloadUrl);
core.info('Extracting downloaded archive...');
if (utils_1.IS_WINDOWS) {
@ -66532,6 +66533,23 @@ function installPyPy(pypyVersion, pythonVersion, architecture, releases) {
yield createPyPySymlink(binaryPath, resolvedPythonVersion);
yield installPip(binaryPath);
return { installDir, resolvedPythonVersion, resolvedPyPyVersion };
}
catch (err) {
if (err instanceof Error) {
// Rate limit?
if (err instanceof tc.HTTPError &&
(err.httpStatusCode === 403 || err.httpStatusCode === 429)) {
core.info(`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`);
}
else {
core.info(err.message);
}
if (err.stack !== undefined) {
core.debug(err.stack);
}
}
throw err;
}
});
}
exports.installPyPy = installPyPy;
@ -66730,7 +66748,9 @@ function installCpythonFromRelease(release) {
return __awaiter(this, void 0, void 0, function* () {
const downloadUrl = release.files[0].download_url;
core.info(`Download from "${downloadUrl}"`);
const pythonPath = yield tc.downloadTool(downloadUrl, undefined, AUTH);
let pythonPath = '';
try {
pythonPath = yield tc.downloadTool(downloadUrl, undefined, AUTH);
core.info('Extract downloaded archive');
let pythonExtractedFolder;
if (utils_1.IS_WINDOWS) {
@ -66741,6 +66761,22 @@ function installCpythonFromRelease(release) {
}
core.info('Execute installation script');
yield installPython(pythonExtractedFolder);
}
catch (err) {
if (err instanceof tc.HTTPError) {
// Rate limit?
if (err.httpStatusCode === 403 || err.httpStatusCode === 429) {
core.info(`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`);
}
else {
core.info(err.message);
}
if (err.stack) {
core.debug(err.stack);
}
}
throw err;
}
});
}
exports.installCpythonFromRelease = installCpythonFromRelease;

View File

@ -46,6 +46,8 @@ export async function installPyPy(
let downloadUrl = `${foundAsset.download_url}`;
core.info(`Downloading PyPy from "${downloadUrl}" ...`);
try {
const pypyPath = await tc.downloadTool(downloadUrl);
core.info('Extracting downloaded archive...');
@ -77,6 +79,25 @@ export async function installPyPy(
await installPip(binaryPath);
return {installDir, resolvedPythonVersion, resolvedPyPyVersion};
} catch (err) {
if (err instanceof Error) {
// Rate limit?
if (
err instanceof tc.HTTPError &&
(err.httpStatusCode === 403 || err.httpStatusCode === 429)
) {
core.info(
`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`
);
} else {
core.info(err.message);
}
if (err.stack !== undefined) {
core.debug(err.stack);
}
}
throw err;
}
}
export async function getAvailablePyPyVersions() {

View File

@ -72,7 +72,9 @@ export async function installCpythonFromRelease(release: tc.IToolRelease) {
const downloadUrl = release.files[0].download_url;
core.info(`Download from "${downloadUrl}"`);
const pythonPath = await tc.downloadTool(downloadUrl, undefined, AUTH);
let pythonPath = '';
try {
pythonPath = await tc.downloadTool(downloadUrl, undefined, AUTH);
core.info('Extract downloaded archive');
let pythonExtractedFolder;
if (IS_WINDOWS) {
@ -83,4 +85,20 @@ export async function installCpythonFromRelease(release: tc.IToolRelease) {
core.info('Execute installation script');
await installPython(pythonExtractedFolder);
} catch (err) {
if (err instanceof tc.HTTPError) {
// Rate limit?
if (err.httpStatusCode === 403 || err.httpStatusCode === 429) {
core.info(
`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`
);
} else {
core.info(err.message);
}
if (err.stack) {
core.debug(err.stack);
}
}
throw err;
}
}