mirror of https://github.com/embarklabs/embark.git
fix callback already called on file download fail
This commit is contained in:
parent
0429703790
commit
e1c5487ba4
|
@ -73,15 +73,25 @@ class File {
|
|||
});
|
||||
},
|
||||
function downloadTheFile(next) {
|
||||
let alreadyCalledBack = false;
|
||||
function doCallback(err) {
|
||||
if (alreadyCalledBack) {
|
||||
return;
|
||||
}
|
||||
alreadyCalledBack = true;
|
||||
next(err);
|
||||
}
|
||||
request(url)
|
||||
.on('response', function (response) {
|
||||
if (response.statusCode !== 200) {
|
||||
next('Getting file returned code ' + response.statusCode);
|
||||
doCallback('Getting file returned code ' + response.statusCode);
|
||||
}
|
||||
})
|
||||
.on('error', next)
|
||||
.on('error', doCallback)
|
||||
.pipe(fs.createWriteStream(filename))
|
||||
.on('finish', next);
|
||||
.on('finish', () => {
|
||||
doCallback();
|
||||
});
|
||||
},
|
||||
function readFile(next) {
|
||||
fs.readFile(filename, next);
|
||||
|
|
Loading…
Reference in New Issue