feat: handle GitHub API rate limits with user-visible feedback (#93)#129
feat: handle GitHub API rate limits with user-visible feedback (#93)#129Harsh-Codes-77 wants to merge 24 commits into
Conversation
|
@Harsh-Codes-77 is attempting to deploy a commit to the PRIYANSHU DOSHI's projects Team on Vercel. A member of the Team first needs to authorize it. |
Priyanshu-byte-coder
left a comment
There was a problem hiding this comment.
Good direction — centralised githubFetch with rate-limit detection and a countdown banner are exactly the right patterns. Three things to fix:
1. Merge conflict — needs rebase
Several files this PR touches (streak/route.ts, contributions/route.ts, ContributionGraph.tsx, PRMetrics.tsx) were recently updated in main. Please rebase:
git fetch origin
git rebase origin/main
git push --force-with-leaseWhen resolving streak/route.ts and contributions/route.ts keep order=desc (the fix from main) — do not revert it back to order=asc.
2. RateLimitBanner uses hardcoded Tailwind colors
className="border-yellow-300 bg-yellow-50 text-yellow-800 hover:bg-yellow-100"These don't adapt to dark mode. Use CSS vars instead, e.g.:
className="rounded-lg border border-amber-500/30 bg-amber-500/10 p-4 text-amber-500"(Same pattern already used by StreakAtRiskBanner.)
3. Missing !r.ok general error check in components
The rate-limit path only catches 429. Other errors (502, 401 token expiry) should still trigger the existing error state. Keep the if (!r.ok) throw guard alongside the 429 check, or return the error from the API and check it in the component.
Priyanshu-byte-coder
left a comment
There was a problem hiding this comment.
Two issues blocking merge:
1. Rebase needed — StreakTracker.tsx conflicts with main
The StreakTracker.tsx in your branch is based on an older version that is missing features already merged into main (last-updated timestamp, copy-to-clipboard, freeze cancellation UI). Your changes will overwrite those. Please rebase on current main and resolve the conflicts.
2. Streak route conflict
src/app/api/metrics/streak/route.ts — main already has order=desc applied. Your githubFetch refactor is good, but make sure the rebase doesn't duplicate or lose that fix.
The githubFetch utility, RateLimitBanner with opacity-based amber colours, and the 429-specific handling are all solid — just need a clean rebase.
9f5bd69 to
0838cf0
Compare
|
Hi @Harsh-Codes-77 — this PR has merge conflicts across several files. Please rebase your branch: git fetch upstream
git rebase upstream/main
# resolve conflicts, then:
git push --force-with-leaseOnce rebased, we'll do a full review. |
0838cf0 to
aa31819
Compare
|
PR has conflicts with Also, two color issues to fix before merge:
|
…ue Metrics widget
- ContributionGraph.tsx: Use main's version as base + add 429 rate limit detection - TopRepos.tsx: Use main's version as base + add 429 rate limit detection in both fetch functions - RateLimitBanner.tsx: Fix text color from amber-200/100 to amber-700 for readability on light background All changes maintain main's functionality while adding explicit rate limit handling.
3cb2278 to
634ecae
Compare
GitHub API Rate Limit Handling — Feature Summary
This implementation adds comprehensive rate limit detection and user-visible feedback for GitHub API calls across the DevTrack dashboard.
Problem Solved
GitHub's API has strict rate limits (60 req/hour for unauthenticated, 5000 for authenticated). Without handling, users would see generic "GitHub API error" messages when limits are hit, with no indication of when the API will be available again.
Solution Overview
1. Centralized Rate Limit Detection (githubFetch.ts)
X-RateLimit-Remaining: 0headerX-RateLimit-Resetheader (Unix seconds)RateLimitErrorwithresetAttimestamp for upstream handling2. API Routes Updated (5 endpoints)
All metrics endpoints now:
githubFetch()instead of rawfetch(){ error: "rate_limited", resetAt: number }when rate limited3. User-Facing Countdown Banner (RateLimitBanner.tsx)
4. Components Enhanced (5 widgets)
All dashboard components now:
resetAttimestamp in local state<RateLimitBanner>instead of normal content when rate limitedKey Benefits
✅ Users know when to retry — Exact reset time visible
✅ Automatic countdown — Clear "X minutes" indicator updates live
✅ Single source of truth — Rate limit logic in one place, no duplication
✅ Backward compatible — Other errors still show generic error message
✅ Type-safe — Full TypeScript coverage, no
anytypes✅ Zero dependencies — Uses standard Fetch API and React hooks