Skip to content

Commit

Permalink
handle error with bundlephobia (#1990)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeniau committed Feb 26, 2024
1 parent bbd8fc9 commit fc17340
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions resources/dist-stats.mjs
Expand Up @@ -26,9 +26,25 @@ let bundlephobaInfoCache;

async function bundlephobaInfo(key) {
if (!bundlephobaInfoCache) {
bundlephobaInfoCache = await fetch(
`https://bundlephobia.com/api/size?package=immutable@${VERIFY_AGAINST_VERSION}`
).then(res => res.json());
try {
const res = await fetch(
`https://bundlephobia.com/api/size?package=immutable@${VERIFY_AGAINST_VERSION}`
);

console.log(res.status);

if (res.status !== 200) {
throw new Error(
`Unable to fetch bundlephobia in dist-stats.mjs. Status code is "${res.status}"`
);
}

bundlephobaInfoCache = await res.json();
} catch (err) {
console.error(err.message);

throw err;
}
}

return bundlephobaInfoCache[key];
Expand Down

0 comments on commit fc17340

Please sign in to comment.