Skip to content

Commit

Permalink
feat: more friendly warning when fetch npm info got error
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 committed Feb 26, 2017
1 parent 5e6437d commit 99035c9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/init_command.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,15 +452,19 @@ module.exports = class Command {
* @return {Object} pkgInfo
*/
* getPackageInfo(pkgName, withFallback) {
this.log(`fetching npm info of ${pkgName}`);
try {
const result = yield urllib.request(`${this.registryUrl}/${pkgName}/latest`, {
dataType: 'json',
followRedirect: true,
});
if (result.status !== 200) {
throw new Error(`npm info ${pkgName} got error: ${result.status}, ${result.data.reason}`);
}
return result.data;
} catch (err) {
if (withFallback) {
this.log('use fallback from ${pkgName}');
this.log(`use fallback from ${pkgName}`);
return require(`${pkgName}/package.json`);
} else {
throw err;
Expand Down

0 comments on commit 99035c9

Please sign in to comment.