Commit fc3ede0
authored
feat: exponential backoff retry for GitHub API calls (JhaSourav07#86)
## Description
Fixes JhaSourav07#50
Adds a `fetchWithRetry` utility that wraps all GitHub API `fetch` calls
with exponential backoff. Retries only on network errors, 429 (rate
limit), and 5xx server errors — up to 3 times with 500ms → 1s → 2s
delays. All 4xx client errors (401, 403, 404, 422, etc.) return
immediately without retrying to avoid duplicate requests on
non-transient failures.
## Pillar
- [ ] 🎨 Pillar 1 — New Theme Design
- [ ] 📐 Pillar 2 — Geometric SVG Improvement
- [ ] 🕐 Pillar 3 — Timezone Logic Optimization
- [x] 🛠️ Other (Bug fix, refactoring, docs)
## Visual Preview
No SVG visual changes — this is a backend reliability improvement. The
badge output is identical; the fix improves resilience when GitHub API
returns transient 502/503 errors or drops connections.
**Retry behaviour:**
| Condition | Action |
|---|---|
| Network error | Retry with backoff (500ms → 1s → 2s) |
| 5xx server error | Retry with backoff |
| 429 Too Many Requests | Retry with backoff |
| 4xx client error (401, 403, 404, 422 …) | Return immediately — no
retry |
| 2xx success | Return immediately |
## 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` and `npm run lint` locally and
resolved all errors (CI will fail otherwise).
- [x] My commits follow the Conventional Commits format (e.g.,
`feat(themes): ...`, `fix(calculate): ...`).
- [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 "premium quality" aesthetic
standard (no raw elements, smooth animations, correct fonts).1 file changed
Lines changed: 42 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
12 | 45 | | |
13 | 46 | | |
14 | 47 | | |
| |||
91 | 124 | | |
92 | 125 | | |
93 | 126 | | |
94 | | - | |
| 127 | + | |
95 | 128 | | |
96 | 129 | | |
97 | 130 | | |
| |||
133 | 166 | | |
134 | 167 | | |
135 | 168 | | |
136 | | - | |
| 169 | + | |
137 | 170 | | |
138 | 171 | | |
139 | 172 | | |
| |||
163 | 196 | | |
164 | 197 | | |
165 | 198 | | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
170 | 206 | | |
171 | 207 | | |
172 | 208 | | |
| |||
0 commit comments