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 Mar 1, 2017
1 parent 5e6437d commit 5713120
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/init_command.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const os = require('os');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const rimraf = require('rimraf');
Expand Down Expand Up @@ -452,15 +453,17 @@ 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,
});
assert(result.status === 200, `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 5713120

Please sign in to comment.