Skip to content

Commit

Permalink
fix(info): handle 404 with non-empty body (#5903)
Browse files Browse the repository at this point in the history
* fix(info): handle 404 with non-empty body

* fix(info): throw on empty response from registry
  • Loading branch information
imsnif authored and arcanis committed May 29, 2018
1 parent 643deaa commit 4b6a5dd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/cli/commands/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type Config from '../../config.js';
import NpmRegistry from '../../registries/npm-registry.js';
import parsePackageName from '../../util/parse-package-name.js';
const semver = require('semver');
const invariant = require('invariant');

function clean(object: any): any {
if (Array.isArray(object)) {
Expand Down Expand Up @@ -60,11 +61,14 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
const packageInput = NpmRegistry.escapeName(packageName);
const {name, version} = parsePackageName(packageInput);

let result = await config.registries.npm.request(name, {unfiltered: true});
if (!result) {
let result;
try {
result = await config.registries.npm.request(name, {unfiltered: true});
} catch (e) {
reporter.error(reporter.lang('infoFail'));
return;
}
invariant(result, 'result must not be empty');

result = clean(result);

Expand Down

0 comments on commit 4b6a5dd

Please sign in to comment.