fix(cdnjs): datasourceError on unknown error

This commit is contained in:
Rhys Arkins 2020-02-23 20:36:11 +01:00
parent cbee46d014
commit 93d475eeb4
2 changed files with 9 additions and 5 deletions

View file

@ -45,9 +45,11 @@ describe('datasource/cdnjs', () => {
jest.clearAllMocks(); jest.clearAllMocks();
return global.renovateCache.rmAll(); return global.renovateCache.rmAll();
}); });
it('returns null for empty result', async () => { it('throws for empty result', async () => {
got.mockResolvedValueOnce(null); got.mockResolvedValueOnce(null);
expect(await getPkgReleases({ lookupName: 'foo/bar' })).toBeNull(); await expect(
getPkgReleases({ lookupName: 'foo/bar' })
).rejects.toThrowError(DATASOURCE_FAILURE);
}); });
it('returns null for missing fields', async () => { it('returns null for missing fields', async () => {
got.mockResolvedValueOnce({}); got.mockResolvedValueOnce({});
@ -77,7 +79,9 @@ describe('datasource/cdnjs', () => {
got.mockImplementationOnce(() => { got.mockImplementationOnce(() => {
throw new Error(); throw new Error();
}); });
expect(await getPkgReleases({ lookupName: 'foo/bar' })).toBeNull(); await expect(
getPkgReleases({ lookupName: 'foo/bar' })
).rejects.toThrowError(DATASOURCE_FAILURE);
}); });
it('returns null with wrong auth token', async () => { it('returns null with wrong auth token', async () => {
got.mockRejectedValueOnce({ statusCode: 401 }); got.mockRejectedValueOnce({ statusCode: 401 });

View file

@ -101,13 +101,13 @@ export async function getPkgReleases({
) { ) {
throw new DatasourceError(err); throw new DatasourceError(err);
} }
if (err.statusCode === 401) { if (err.statusCode === 401) {
logger.debug(errorData, 'Authorization error'); logger.debug(errorData, 'Authorization error');
} else if (err.statusCode === 404) { } else if (err.statusCode === 404) {
logger.debug(errorData, 'Package lookup error'); logger.debug(errorData, 'Package lookup error');
} else { } else {
logger.warn(errorData, 'CDNJS lookup failure: Unknown error'); logger.debug(errorData, 'CDNJS lookup failure: Unknown error');
throw new DatasourceError(err);
} }
} }