fix(packagist): gracefully handle ETIMEDOUT and 403

This commit is contained in:
Rhys Arkins 2019-07-02 07:20:01 +02:00
parent 3f6b37f1ea
commit 490bc3567a
2 changed files with 18 additions and 2 deletions

View file

@ -52,7 +52,11 @@ async function getRegistryMeta(regUrl) {
}
return meta;
} catch (err) {
if (err.statusCode === 401) {
if (err.code === 'ETIMEDOUT') {
logger.info({ regUrl }, 'Packagist timeout');
return null;
}
if (err.statusCode === 401 || err.statusCode === 403) {
logger.info({ regUrl }, 'Unauthorized Packagist repository');
return null;
}

View file

@ -89,10 +89,22 @@ describe('datasource/packagist', () => {
});
expect(res).toMatchSnapshot();
});
it('handles timeouts', async () => {
got.mockImplementationOnce(() =>
Promise.reject({
code: 'ETIMEDOUT',
})
);
const res = await datasource.getPkgReleases({
...config,
lookupName: 'vendor/package-name2',
});
expect(res).toBeNull();
});
it('handles auth rejections', async () => {
got.mockImplementationOnce(() =>
Promise.reject({
statusCode: 401,
statusCode: 403,
})
);
const res = await datasource.getPkgReleases({