Permalink
Browse files

refactor .getJSON() callback

  • Loading branch information...
1 parent a96d9ee commit 78f68fac6453a37a154848e6931ef651e260b4bd @tj tj committed Mar 26, 2013
Showing with 7 additions and 10 deletions.
  1. +7 −10 lib/Package.js
View
@@ -158,18 +158,15 @@ Package.prototype.getJSON = function(fn){
req.set('Accept-Encoding', 'gzip');
req.end(function(res){
- if (res.ok) {
+ if (res.error) return fn(error(res, url));
+ try {
debug('got %s', url);
- try {
- var json = JSON.parse(res.text);
- } catch (err) {
- err.message += ' in ' + url;
- return fn(err);
- }
- fn(null, json);
- } else {
- fn(error(res, url));
+ var json = JSON.parse(res.text);
+ } catch (err) {
+ err.message += ' in ' + url;
+ return fn(err);
}
+ fn(null, json);
});
req.on('error', function(err){

0 comments on commit 78f68fa

Please sign in to comment.