Commit 9cf71e1
authored
feat(github): add AbortController timeout to fetchWithRetry with per-endpoint defaults (JhaSourav07#423)
## Description
Fixes JhaSourav07#273
- Added two constants `GRAPHQL_TIMEOUT_MS` and `REST_TIMEOUT_MS` for the
default timeouts
- Added optional `timeoutMs` parameter to `fetchWithRetry` for `per-call
override`
- Added `AbortController` with `setTimeout` — fires after the resolved
timeout and aborts the fetch
- Passed `signal: controller.signal` into the fetch options
- `clearTimeout` called in both success and error paths to avoid memory
leaks
- `AbortError` is caught specifically and throws a clean typed message
"GitHub API request timed out after Xs"
- Recursive retry calls pass `timeoutMs` through so each attempt gets
its own fresh timeout window
- All existing retry logic for network errors and 5xx remains completely
intact
- No other files need changes — `route.ts` error SVG already catches all
Error instances and renders them cleanly.
## Pillar
- 🛠️ Other (Bug fix, refactoring, docs)
## Visual Preview
- With `GRAPHQL_TIMEOUT_MS` and `REST_TIMEOUT_MS` set to a very small
value like `1`:
<img width="508" height="313" alt="Screenshot 2026-05-24 at 8 50 32 PM"
src="https://github.com/user-attachments/assets/34f91c6c-2b64-4855-abc4-87c7f6b29c2b"
/>
<img width="516" height="210" alt="Screenshot 2026-05-24 at 8 50 52 PM"
src="https://github.com/user-attachments/assets/4789b216-c796-48de-9faf-6927535ef5f5"
/>
- With `GRAPHQL_TIMEOUT_MS` and `REST_TIMEOUT_MS` set to appropriate
values like `8000` & `5000` respectively:
<img width="668" height="546" alt="Screenshot 2026-05-24 at 8 51 35 PM"
src="https://github.com/user-attachments/assets/44d7383d-e2bd-4b19-b4cf-71fbefe7a3bb"
/>
## Checklist before requesting a review:
- I have read the `CONTRIBUTING.md` file.
- I have tested these changes locally
(`localhost:3000/api/streak?user=YOUR_USERNAME`).
- I have run `npm run format` and `npm run lint` locally and resolved
all errors.
- My commits follow the Conventional Commits format.
- I have starred the repo.
- I have made sure that i have only one commit to merge in this PR.
- The SVG output matches the CommitPulse "premium quality" aesthetic
standard.2 files changed
Lines changed: 25 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
16 | 18 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | 19 | | |
23 | 20 | | |
24 | 21 | | |
25 | | - | |
| 22 | + | |
| 23 | + | |
26 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
27 | 35 | | |
28 | 36 | | |
29 | | - | |
| 37 | + | |
30 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
31 | 45 | | |
32 | 46 | | |
33 | 47 | | |
34 | 48 | | |
35 | | - | |
| 49 | + | |
36 | 50 | | |
37 | 51 | | |
| 52 | + | |
| 53 | + | |
38 | 54 | | |
39 | 55 | | |
40 | 56 | | |
41 | 57 | | |
42 | 58 | | |
43 | 59 | | |
44 | | - | |
| 60 | + | |
45 | 61 | | |
46 | 62 | | |
47 | 63 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments