Skip to content

Commit

Permalink
Merge pull request #91 from jackfranklin/deal-with-api-down
Browse files Browse the repository at this point in the history
Deal with API errors
  • Loading branch information
jackfranklin committed Jun 22, 2014
2 parents 28d1efc + 5a9bcc9 commit e7b910a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
4 changes: 3 additions & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ var cli = {
this.stopTicker();
if(err) {
this.log("Error: " + err.message, "red");
this.log("Did you only use one colon instead of two to separate the search term and file name?");
if(!err.statusCode) {
this.log("Did you only use one colon instead of two to separate the search term and file name?");
}
return;
}
if(this.output && !this.dryRun) shell.mkdir("-p", this.output);
Expand Down
32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@
"url": "git@github.com:jackfranklin/pulldown.git"
},
"dependencies": {
"request": "~2.10.0",
"request": "2.10.0",
"shelljs": "0.0.6",
"unzip": "~0.1.8",
"pulldown-resolve": "~0.1.2",
"pulldown-middle-man": "0.1.0",
"async": "~0.2.8",
"underscore": "~1.4.4",
"chalk": "~0.2.0",
"update-notifier": "~0.1.5",
"yargs": "~1.1.3"
"unzip": "0.1.8",
"pulldown-resolve": "0.1.2",
"async": "0.2.8",
"underscore": "1.4.4",
"chalk": "0.2.0",
"update-notifier": "0.1.5",
"yargs": "1.1.3",
"pulldown-middle-man": "0.2.0"
},
"devDependencies": {
"mocha": "~1.10.0",
"sinon": "~1.7.2",
"rimraf": "~2.2.0",
"nock": "~0.22.1",
"grunt": "~0.4.1",
"grunt-contrib-jshint": "~0.6.3",
"grunt-simple-mocha": "~0.4.0"
"mocha": "1.10.0",
"sinon": "1.7.2",
"rimraf": "2.2.0",
"nock": "0.22.1",
"grunt": "0.4.1",
"grunt-contrib-jshint": "0.6.3",
"grunt-simple-mocha": "0.4.0"
}
}
29 changes: 23 additions & 6 deletions pulldown.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ pulldown.ls = function(done) {

pulldown.processDownload = function(userArgs, done) {
this.localJson = this.getLocalJson();
this.processUserArgs(userArgs, function(urls) {
this.processUserArgs(userArgs, function(err, urls) {
if(err) {
return done({
statusCode: 503,
message: 'Our API returned a 503. It may be offline currently. Please check the Pulldown issue tracker [https://github.com/jackfranklin/pulldown/issues?state=open] and report this if it hasn\'t been already.'
});
}
this.downloadFiles(urls, done);
}.bind(this));
};
Expand All @@ -51,10 +57,14 @@ pulldown.getLocalJson = function() {

pulldown.processUserArgs = function(userArgs, callback) {
async.map(userArgs, function(item, done) {
this.parsePackageArgument(item, function(data) {
done(null, data);
this.parsePackageArgument(item, function(err, data) {
done(err, data);
}.bind(this));
}.bind(this), function(err, results) {
if(err) {
callback(err);
return;
}
results = _.flatten(results);

// need to make sure each obj in results is uniq
Expand All @@ -63,7 +73,7 @@ pulldown.processUserArgs = function(userArgs, callback) {
var jsonResults = results.map(function(item) { return JSON.stringify(item); });
results = _.uniq(jsonResults).map(function(item) { return JSON.parse(item); });

callback(results);
callback(null, results);
});
};

Expand All @@ -75,14 +85,21 @@ pulldown.parsePackageArgument = function(searchTerm, callback) {
resolve.identifier(searchTerm, {
registry: this.localJson,
helper: function(identifier, callback) {
middleMan.set(identifier, function(data) {
middleMan.set(identifier, function(err, data) {
if(err) {
return callback(err);
}
data = data.map(function(item) {
return item[0] === "/" ? "https:" + item : item;
});
callback(null, data);
});
}
}, function(err, set) {
if(err) {
return callback(err);
}

set = set.map(function(item) {
return item[0] === "/" ? "https:" + item : item;
});
Expand All @@ -93,7 +110,7 @@ pulldown.parsePackageArgument = function(searchTerm, callback) {
if(!set.length) {
resp.push({ searchTerm: searchTerm, found: false });
}
callback(resp);
callback(null, resp);
});
};

Expand Down

0 comments on commit e7b910a

Please sign in to comment.