Skip to content
This repository has been archived by the owner on Mar 27, 2019. It is now read-only.

Commit

Permalink
add error(res, url) helper
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Nov 2, 2012
1 parent ce98a8d commit 89d5827
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/Package.js
Expand Up @@ -154,10 +154,7 @@ Package.prototype.getJSON = function(fn){
}
fn(null, json);
} else {
var name = http.STATUS_CODES[res.status];
var err = new Error('failed to fetch ' + url + ', got ' + res.status + ' "' + name + '"');
err.status = res.status;
fn(err);
fn(error(res, url));
}
});

Expand Down Expand Up @@ -323,3 +320,19 @@ Package.prototype.reallyInstall = function(){
});
});
};

/**
* Return an error for `res` / `url`.
*
* @param {Response} res
* @param {String} url
* @return {Error}
* @api private
*/

function error(res, url) {
var name = http.STATUS_CODES[res.status];
var err = new Error('failed to fetch ' + url + ', got ' + res.status + ' "' + name + '"');
err.status = res.status;
return err;
}

0 comments on commit 89d5827

Please sign in to comment.