Skip to content

Commit

Permalink
fix(downloads): be resilient for 404 or downloads endpoint for a chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
Haroenv committed Apr 16, 2017
1 parent d157450 commit 866fbcf
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion npm.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import got from 'got';
import c from './config.js';
import { chunk } from 'lodash';
import numeral from 'numeral';

import c from './config.js';
import log from './log.js';

export function info() {
return got(c.npmRegistryEndpoint, {
json: true,
Expand Down Expand Up @@ -31,6 +33,19 @@ export function getDownloads(pkgs) {
...pkgsNamesChunks.map(pkgsNames =>
got(`${c.npmDownloadsEndpoint}/point/last-month/${pkgsNames}`, {
json: true,
}).catch(e => {
log.warn(
`Something went wrong asking the downloads for \n${Array.from(pkgsNames).join(',')} \n${e}`
);
return {
body: Array.from(pkgsNames).reduce((acc, current) => {
acc[current] = {
downloads: 0,
package: current,
};
return acc;
}, {}),
};
})
),
]).then(([
Expand Down

0 comments on commit 866fbcf

Please sign in to comment.