Skip to content

Commit

Permalink
fix(cdnjs): datasourceError on unknown error
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Feb 23, 2020
1 parent cbee46d commit 93d475e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions lib/datasource/cdnjs/index.spec.ts
Expand Up @@ -45,9 +45,11 @@ describe('datasource/cdnjs', () => {
jest.clearAllMocks();
return global.renovateCache.rmAll();
});
it('returns null for empty result', async () => {
it('throws for empty result', async () => {
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 () => {
got.mockResolvedValueOnce({});
Expand Down Expand Up @@ -77,7 +79,9 @@ describe('datasource/cdnjs', () => {
got.mockImplementationOnce(() => {
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 () => {
got.mockRejectedValueOnce({ statusCode: 401 });
Expand Down
4 changes: 2 additions & 2 deletions lib/datasource/cdnjs/index.ts
Expand Up @@ -101,13 +101,13 @@ export async function getPkgReleases({
) {
throw new DatasourceError(err);
}

if (err.statusCode === 401) {
logger.debug(errorData, 'Authorization error');
} else if (err.statusCode === 404) {
logger.debug(errorData, 'Package lookup error');
} else {
logger.warn(errorData, 'CDNJS lookup failure: Unknown error');
logger.debug(errorData, 'CDNJS lookup failure: Unknown error');
throw new DatasourceError(err);
}
}

Expand Down

0 comments on commit 93d475e

Please sign in to comment.