diff --git a/src/pages/ContributorProfile/ContributorProfile.tsx b/src/pages/ContributorProfile/ContributorProfile.tsx index ed1b714d..e9dc1643 100644 --- a/src/pages/ContributorProfile/ContributorProfile.tsx +++ b/src/pages/ContributorProfile/ContributorProfile.tsx @@ -14,27 +14,58 @@ type Profile = { bio: string; }; +// --- FIX: Added separate error type to distinguish 404 vs other failures --- +type ErrorType = "not_found" | "api_error" | null; + export default function ContributorProfile() { const { username } = useParams(); const [profile, setProfile] = useState(null); const [prs, setPRs] = useState([]); const [loading, setLoading] = useState(true); + // --- FIX: New error state --- + const [error, setError] = useState(null); useEffect(() => { async function fetchData() { if (!username) return; + // --- FIX: Reset error on each fetch --- + setError(null); + try { const userRes = await fetch(`https://api.github.com/users/${username}`); + + if (!userRes.ok) { + if (userRes.status === 404) { + // --- FIX: 404 → "not_found", not a generic error --- + setError("not_found"); + } else { + // --- FIX: Rate limit, server error, etc. → "api_error" --- + setError("api_error"); + } + setProfile(null); + setPRs([]); + return; + } + const userData = await userRes.json(); setProfile(userData); 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) { + setPRs([]); + toast.error("Failed to load pull requests."); + } else { + const prsData = await prsRes.json(); + setPRs(prsData.items ?? []); + } } catch { + // --- FIX: Network/connection failures → "api_error" --- + setError("api_error"); + setProfile(null); + setPRs([]); toast.error("Failed to fetch user data."); } finally { setLoading(false); @@ -51,10 +82,24 @@ export default function ContributorProfile() { if (loading) return
Loading...
; - if (!profile) + // --- FIX: Show correct message based on error type --- + if (error === "not_found") { + return ( +
+ User not found. +
+ ); + } + + if (error === "api_error") { return ( -
User not found.
+
+ Unable to load contributor profile. Please try again later. +
); + } + + if (!profile) return null; return (
@@ -98,4 +143,4 @@ export default function ContributorProfile() { )}
); -} +} \ No newline at end of file