Commit d5abb08
authored
fix(api): classify stats route GitHub errors (JhaSourav07#2199)
## Description
Fixes JhaSourav07#2198
## Pillar
- [x] 🛠️ Other (Bug fix, refactoring, docs)
## What changed
The `/api/stats` route was returning `500 Internal Server Error` for
every exception from `fetchGitHubContributions`, including normal
GitHub-side cases like missing users and API rate limits.
This PR mirrors the error classification already used by the dashboard
API route:
- GitHub not-found / could-not-resolve errors now return `404` with
`User not found`
- GitHub rate-limit style errors now return `403` with the existing
rate-limit message
- Unknown errors still fall back to `500`
I also added route tests for the new not-found and rate-limit branches
so the behavior stays explicit.
## Visual Preview
N/A — JSON API status-code fix only.
## Local verification
- `npm run test -- app/api/stats/route.test.ts` passed
- `npm run format:check` passed
- `npm run lint` passed with one existing warning in
`components/WallOfLove.tsx`
- `npm run typecheck` passed
- `npm run test` passed: 83 files, 1394 tests
- `npm run test:coverage` completed; current repo-wide branch coverage
reports 66.98% on latest main
- `npm run build` currently fails on clean `origin/main` too with only
`Build failed because of webpack errors`, so that appears unrelated to
this PR
## GSSoC 2026
This is raised and fixed under GSSoC 2026. Please add the relevant
GSSoC/level labels if they do not sync from the issue automatically.
## Checklist before requesting a review:
- [x] I have read the `CONTRIBUTING.md` file.
- [x] I have tested these changes locally
(`localhost:3000/api/streak?user=YOUR_USERNAME`).
- [x] I have run `npm run format` / `npm run format:check` and `npm run
lint` locally.
- [x] I have run `npm run test` and all tests pass locally.
- [x] My commits follow the Conventional Commits format.
- [x] I have updated `README.md` if I added a new theme or URL
parameter.
- [x] I have starred the repo.
- [x] I have made sure that I have only one commit to merge in this PR.
- [x] The SVG output matches the CommitPulse quality standard.2 files changed
Lines changed: 41 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
161 | 183 | | |
162 | 184 | | |
163 | 185 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
74 | 93 | | |
75 | 94 | | |
76 | 95 | | |
0 commit comments