refactor: info not warn if npm 401 response

This commit is contained in:
Rhys Arkins 2017-12-27 06:40:24 +01:00
parent 976f2ac57e
commit 383302d433
2 changed files with 11 additions and 0 deletions

View file

@ -84,6 +84,10 @@ async function getDependency(name) {
logger.trace({ dep }, 'dep'); logger.trace({ dep }, 'dep');
return dep; return dep;
} catch (err) { } catch (err) {
if (err.statusCode === 401) {
logger.info({ err, name }, `Dependency lookup unauthorized`);
return null;
}
if (err.statusCode === 404) { if (err.statusCode === 404) {
logger.info({ err, name }, `Dependency not found`); logger.info({ err, name }, `Dependency not found`);
return null; return null;

View file

@ -45,6 +45,13 @@ describe('api/npm', () => {
const res = await npm.getDependency('foobarhome'); const res = await npm.getDependency('foobarhome');
expect(res).toMatchSnapshot(); expect(res).toMatchSnapshot();
}); });
it('should return null if lookup fails 401', async () => {
nock('https://registry.npmjs.org')
.get('/foobar')
.reply(401);
const res = await npm.getDependency('foobar');
expect(res).toBeNull();
});
it('should return null if lookup fails', async () => { it('should return null if lookup fails', async () => {
nock('https://registry.npmjs.org') nock('https://registry.npmjs.org')
.get('/foobar') .get('/foobar')