Skip to content

Commit

Permalink
Merge branch 'main' into docs/useMutation-exmaple-params-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ElayGelbart authored Nov 6, 2024
2 parents a2ad89b + 9971e7b commit 7d6a147
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions docs/scripts/update-contributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,25 @@ if (!GITHUB_TOKEN) {
);
}

class UserFetchError extends Error {
/**
* @param {string} message
* @param {Response} response
*/
constructor(message, response) {
super(message);
this.name = "UserFetchError";
this.response = response;
}

/**
* @returns {boolean}
*/
get notFound() {
return this.response.status === 404;
}
}

async function fetchUserInfo(username) {
const res = await fetch(`https://api.github.com/users/${username}`, {
headers: {
Expand All @@ -23,7 +42,7 @@ async function fetchUserInfo(username) {
},
});
if (!res.ok) {
throw new Error(`${res.url} responded with ${res.status}`);
throw new UserFetchError(`${res.url} responded with ${res.status}`, res);
}
return await res.json();
}
Expand Down Expand Up @@ -165,7 +184,7 @@ const CONTRIBUTORS = {
"illright",
]),
"openapi-react-query": new Set(["drwpow", "kerwanp", "yoshi2no", "elaygelbart"]),
"swr-openapi": new Set(["htunnicliff"])
"swr-openapi": new Set(["htunnicliff"]),
};

async function main() {
Expand Down Expand Up @@ -197,6 +216,11 @@ async function main() {
console.log(`[${i}/${total}] Updated for ${username}`);
fs.writeFileSync(new URL("../data/contributors.json", import.meta.url), JSON.stringify(data)); // update file while fetching (sync happens safely in between fetches)
} catch (err) {
if (err instanceof UserFetchError && err.notFound) {
console.warn(`[${i}/${total}] (Skipped ${username}, not found)`);
continue;
}

throw new Error(err);
}
}
Expand Down

0 comments on commit 7d6a147

Please sign in to comment.