From 451a6380c6bd7f79c0b4a9bdfdb1bb7d49839b0b Mon Sep 17 00:00:00 2001
From: Almeida
Date: Wed, 10 Dec 2025 22:03:32 +0000
Subject: [PATCH] fix: handle github api errors gracefully (#11357)
* fix: handle github api errors gracefully
* fix: remove forks and improve log
---
apps/guide/src/components/GitHubInfo.tsx | 35 +++++++++---------------
1 file changed, 13 insertions(+), 22 deletions(-)
diff --git a/apps/guide/src/components/GitHubInfo.tsx b/apps/guide/src/components/GitHubInfo.tsx
index 62a610e75..b34d5ee37 100644
--- a/apps/guide/src/components/GitHubInfo.tsx
+++ b/apps/guide/src/components/GitHubInfo.tsx
@@ -5,14 +5,7 @@ import { Star } from 'lucide-react';
import { type AnchorHTMLAttributes } from 'react';
import { twMerge as cn } from 'tailwind-merge';
-async function getRepoStarsAndForks(
- owner: string,
- repo: string,
- token?: string,
-): Promise<{
- forks: number;
- stars: number;
-}> {
+async function getRepoStars(owner: string, repo: string, token?: string): Promise<{ stars: number } | null> {
const endpoint = `https://api.github.com/repos/${owner}/${repo}`;
const headers = new Headers({
'Content-Type': 'application/json',
@@ -24,21 +17,18 @@ async function getRepoStarsAndForks(
const response = await fetch(endpoint, {
headers,
next: {
- revalidate: 60,
+ revalidate: 24 * 60 * 60,
},
- } as RequestInit);
+ });
if (!response.ok) {
const message = await response.text();
-
- throw new Error(`Failed to fetch repository data: ${message}`);
+ console.warn(`Failed to fetch repository data (${response.status}):`, message);
+ return null;
}
const data = await response.json();
- return {
- stars: data.stargazers_count,
- forks: data.forks_count,
- };
+ return { stars: data.stargazers_count };
}
export async function GithubInfo({
@@ -51,8 +41,7 @@ export async function GithubInfo({
readonly repo: string;
readonly token?: string;
}) {
- const { stars } = await getRepoStarsAndForks(owner, repo, token);
- const humanizedStars = humanizeNumber(stars);
+ const repoData = await getRepoStars(owner, repo, token);
return (
{owner}/{repo}
-
-
- {humanizedStars}
-
+ {repoData ? (
+
+
+ {humanizeNumber(repoData.stars)}
+
+ ) : null}
);
}