From 99529aa970735680c46706af66b6a05bd61ebf6f Mon Sep 17 00:00:00 2001 From: Mayuri Gade Date: Sun, 24 May 2026 18:20:31 +0530 Subject: [PATCH] fix(contributor-profile): prevent crashes on failed GitHub API responses --- .../ContributorProfile/ContributorProfile.tsx | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/pages/ContributorProfile/ContributorProfile.tsx b/src/pages/ContributorProfile/ContributorProfile.tsx index ed1b714d..cab7fe03 100644 --- a/src/pages/ContributorProfile/ContributorProfile.tsx +++ b/src/pages/ContributorProfile/ContributorProfile.tsx @@ -26,14 +26,28 @@ export default function ContributorProfile() { try { const userRes = await fetch(`https://api.github.com/users/${username}`); + if (!userRes.ok) { + if (userRes.status === 404) { + setProfile(null); + setPRs([]); + return; + } + throw new Error(`Failed to load user (${userRes.status})`); + } const userData = await userRes.json(); - setProfile(userData); + setProfile(userData as Profile); const prsRes = await fetch( `https://api.github.com/search/issues?q=author:${username}+type:pr` ); - const prsData = await prsRes.json(); - setPRs(prsData.items); + if (!prsRes.ok) { + // avoid crashing — show empty PR list and notify user + setPRs([]); + toast.error("Failed to load pull requests."); + } else { + const prsData = await prsRes.json(); + setPRs(prsData.items ?? []); + } } catch { toast.error("Failed to fetch user data."); } finally {