diff --git a/src/pages/Contributors/Contributors.tsx b/src/pages/Contributors/Contributors.tsx index d4fee52c..286cc45b 100644 --- a/src/pages/Contributors/Contributors.tsx +++ b/src/pages/Contributors/Contributors.tsx @@ -33,12 +33,78 @@ const ContributorsPage = () => { useEffect(() => { const fetchContributors = async () => { try { - const response = await axios.get(GITHUB_REPO_CONTRIBUTORS_URL, { - withCredentials: false, - }); + // REAL API CALL + const response = await axios.get( + GITHUB_REPO_CONTRIBUTORS_URL, + { + withCredentials: false, + } + ); + setContributors(response.data); - } catch { - setError("Failed to fetch contributors. Please try again later."); + + /* + // ================================================== + // TEMPORARY TESTING CODE + // Uncomment this block ONLY if you want to test + // the rate limit UI manually. + // ================================================== + + // // throw { + // // isAxiosError: true, + // // response: { + // // status: 403, + // // headers: { + // // "x-ratelimit-remaining": 0, + // // "x-ratelimit-reset": 1750000000, + // // }, + // // }, + // // }; + + // ================================================== + // */ + } catch (error) { + if (axios.isAxiosError(error)) { + + // GitHub API Rate Limit Error + if (error.response?.status === 403) { + + const remaining = + error.response.headers["x-ratelimit-remaining"]; + + const reset = + error.response.headers["x-ratelimit-reset"]; + + let resetMessage = ""; + + if (reset) { + const resetTime = new Date( + Number(reset) * 1000 + ); + + resetMessage = + ` Try again after ${resetTime.toLocaleTimeString()}.`; + } + + setError( + `GitHub API rate limit exceeded. Remaining requests: ${remaining}.${resetMessage}` + ); + + } else { + + setError( + "Failed to fetch contributors. Please try again later." + ); + + } + + } else { + + setError( + "An unexpected error occurred." + ); + + } } finally { setLoading(false); } @@ -47,18 +113,28 @@ const ContributorsPage = () => { fetchContributors(); }, []); + // Loading UI if (loading) { return ( - + ); } + // Error UI if (error) { return ( - {error} + + {error} + ); } @@ -66,73 +142,100 @@ const ContributorsPage = () => { return (
- + 🤝 Contributors {contributors.map((contributor) => ( - - + + - + + + + {contributor.login} + + + - - - - {contributor.login} - - - - {contributor.contributions} Contributions - - {/* - - Thank you for your valuable contributions to our - community! - */} - - - - - - - + {contributor.contributions} Contributions + + + + + + + + ))} @@ -141,4 +244,4 @@ const ContributorsPage = () => { ); }; -export default ContributorsPage; +export default ContributorsPage; \ No newline at end of file