Skip to content

Commit b265dd0

Browse files
authored
Merge pull request #206 from DavidVujic/retry_download
Retry download if failed
2 parents 88fdb51 + e1c3455 commit b265dd0

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

scripts/helper.js

+16
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@ function exec(action) {
1111
return res.stdout;
1212
}
1313

14+
async function retry(func, ...args) {
15+
let res;
16+
17+
try {
18+
res = await func(...args);
19+
} catch (e) {
20+
shell.echo(e.message);
21+
shell.echo(`Retrying ${func.name}`);
22+
23+
res = await func(...args);
24+
}
25+
26+
return res;
27+
}
28+
1429
module.exports = {
1530
exec,
31+
retry,
1632
};

scripts/prepublish.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const shell = require('shelljs');
44
const decompress = require('decompress');
55
const decompressTargz = require('decompress-targz');
66
const env = require('./env.js');
7-
const { exec } = require('./helper.js');
7+
const { exec, retry } = require('./helper.js');
88

99
function writeFile(url, destination, resolve, reject) {
1010
const file = fs.createWriteStream(destination);
@@ -14,12 +14,12 @@ function writeFile(url, destination, resolve, reject) {
1414
});
1515

1616
req.on('error', (e) => {
17-
file.unlink(destination);
17+
shell.rm(destination);
1818
reject(e);
1919
});
2020

2121
file.on('error', () => {
22-
file.unlink(destination);
22+
shell.rm(destination);
2323
reject(new Error('File error'));
2424
});
2525

@@ -115,7 +115,7 @@ if (env.isVerbose) {
115115

116116
shell.cd(env.workFolder);
117117

118-
download(env.downloadUrl, env.downloadedFileName)
118+
retry(download, env.downloadUrl, env.downloadedFileName)
119119
.then(() => {
120120
validateFile(env.downloadedFileName);
121121

0 commit comments

Comments
 (0)