8000 Handle download HTTP error · akv-platform/setup-python@3939e19 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3939e19

Browse files
committed
Handle download HTTP error
1 parent 13a464f commit 3939e19

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

src/install-python.ts

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,36 @@ export async function installCpythonFromRelease(release: tc.IToolRelease) {
7272
const downloadUrl = release.files[0].download_url;
7373

7474
core.info(`Download from "${downloadUrl}"`);
75-
const pythonPath = await tc.downloadTool(downloadUrl, undefined, AUTH);
76-
core.info('Extract downloaded archive');
77-
let pythonExtractedFolder;
78-
if (IS_WINDOWS) {
79-
pythonExtractedFolder = await tc.extractZip(pythonPath);
80-
} else {
81-
pythonExtractedFolder = await tc.extractTar(pythonPath);
82-
}
75+
let pythonPath = '';
76+
try {
77+
pythonPath = await tc.downloadTool(downloadUrl, undefined, AUTH);
78+
core.info('Extract downloaded archive');
79+
let pythonExtractedFolder;
80+
if (IS_WINDOWS) {
81+
pythonExtractedFolder = await tc.extractZip(pythonPath);
82+
} else {
83+
pythonExtractedFolder = await tc.extractTar(pythonPath);
84+
}
8385

84-
core.info('Execute installation script');
85-
await installPython(pythonExtractedFolder);
86+
core.info('Execute installation script');
87+
await installPython(pythonExtractedFolder);
88+
} catch (err) {
89+
if (err instanceof Error)
90+
{
91+
// Rate limit?
92+
if (
93+
err instanceof tc.HTTPError &&
94+
(err.httpStatusCode === 403 || err.httpStatusCode === 429)
95+
) {
96+
core.info(
97+
`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`
98+
);
99+
} else {
100+
core.info(err.message);
101+
}
102+
if (err.stack !== undefined) {
103+
core.debug(err.stack);
104+
}
105+
}
106+
}
86107
}

0 commit comments

Comments
 (0)
0