Skip to content

feat: add apiClient timeout handling#41

Closed
gaoflow wants to merge 2 commits into
StableRoute-Org:mainfrom
gaoflow:enhancement/api-client-12-timeout-abort
Closed

feat: add apiClient timeout handling#41
gaoflow wants to merge 2 commits into
StableRoute-Org:mainfrom
gaoflow:enhancement/api-client-12-timeout-abort

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 21, 2026

Copy link
Copy Markdown

Summary

  • add a default 10s AbortController timeout to apiFetch, with per-call timeoutMs overrides
  • add a typed ApiTimeoutError and isApiTimeoutError guard
  • combine caller-supplied abort signals with the timeout signal
  • preserve default Content-Type while merging caller headers
  • have useApi abort in-flight requests on cleanup so unmount cancellations do not surface as UI errors
  • cover success requests, env base URL override, POST/PATCH/DELETE wrappers, header merge, network rejection, timeout, external abort, 204, ApiError, and useApi cleanup paths

Closes #12
Closes #15

Tests

  • npm test -- src/lib/__tests__/apiClient.test.ts --runInBand
  • npm test -- src/lib/__tests__/apiClient.test.ts src/lib/__tests__/useApi.test.tsx --runInBand
  • npm run lint
  • npm test -- --runInBand
  • npm run build

@mikewheeleer

Copy link
Copy Markdown
Contributor

hey @gaoflow, thanks for the effort here 🙏 issue #12 isn't assigned to you though — to keep the campaign fair and avoid duplicate work, please claim/get assigned to it first, then open your PR. closing for now; would love to see it back once it's assigned to you 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests for the apiClient request, error, and 204 handling paths Add a request timeout and abort handling to the shared apiClient

2 participants