mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-23 13:48:49 +00:00
Merge pull request #523 from embark-framework/bug_fix/bad-branch
Fix callback already called on file download fail
This commit is contained in:
commit
977b472217
@ -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…
x
Reference in New Issue
Block a user