Skip to content

Commit 5b290fa

Browse files
committed
Fix response headers parsing which fixes contributor counts
1 parent 5b3a470 commit 5b290fa

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/fetcher.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const throttledFetch = throttler(async (url: string) => {
3030

3131
if (GITHUB_TOKEN && /github.com/.test(url)) {
3232
headers.Authorization = `token ${GITHUB_TOKEN}`;
33+
headers.Accept = "application/vnd.github.v3+json";
3334
}
3435

3536
if (/bundlephobia/.test(url)) {
@@ -39,8 +40,9 @@ const throttledFetch = throttler(async (url: string) => {
3940

4041
const fn = async () => {
4142
const res = await fetch(url, { headers });
43+
const resHeaders = Object.fromEntries(res.headers.entries());
4244
const data = await res.json();
43-
return { headers: JSON.parse(JSON.stringify(res.headers)), data };
45+
return { headers: resHeaders, data };
4446
};
4547

4648
return await pRetry(fn, {
@@ -56,9 +58,10 @@ const throttledFetch = throttler(async (url: string) => {
5658
},
5759
});
5860
} catch (err: any) {
59-
const status = err.response?.status;
60-
const headers = JSON.stringify(err.response?.headers, null, " ");
61-
log("failed %s - status=%s, headers=%o - %s", url, status, headers, err);
61+
const res = err.response;
62+
const status = res?.status;
63+
const resHeaders = Object.fromEntries(res?.headers.entries());
64+
log("failed %s - status=%s, headers=%o - %s", url, status, resHeaders, err);
6265
throw err;
6366
}
6467
});

0 commit comments

Comments
 (0)