Skip to content

add shared request timeout and AbortSignal cancellation support - #1383

Open
canicefavour wants to merge 2 commits into
Pulsefy:mainfrom
canicefavour:lumen
Open

canicefavour wants to merge 2 commits into
Pulsefy:mainfrom
canicefavour:lumen

Conversation

@canicefavour

Copy link
Copy Markdown

Refactored lib/api-client.ts to introduce a centralized and resilient request pipeline designed to handle unreliable mobile network conditions more gracefully.

What Was Implemented
Added configurable request timeout handling with a strict default timeout boundary.
Added AbortSignal support to allow in-flight requests to be cancelled when screens or components unmount.
Implemented automatic retry handling for transient failures using exponential backoff with jitter.
Added idempotency protection so automatic retries are limited to safe/idempotent HTTP methods, preventing unintended duplicate mutations.
Added network connectivity checks to prevent unnecessary retry loops while the device is offline.
Introduced distinct error states for timeout, offline, network, and cancellation scenarios so consuming UI components can provide more meaningful feedback.
Ensured pending retry delays and active requests are cancelled when the caller's abort signal is triggered.
Centralized request lifecycle handling so retry, timeout, connectivity, and cancellation behavior is consistently applied across API requests.
Testing

Added comprehensive API client tests covering:

Successful retries after transient failures.
Maximum retry/give-up behavior.
Idempotency enforcement for non-retryable requests.
Request cancellation through AbortSignal.
Offline connectivity gating.
Timeout error handling and distinct timeout state.
Result

The mobile API layer is now more resilient to flaky connectivity, avoids unnecessary request storms and offline retry loops, and properly cleans up requests when consumers are unmounted. The centralized architecture also provides predictable, typed error states for better downstream UI handling.

Closes #1191

@drips-wave

drips-wave Bot commented Aug 31, 2026

Copy link
Copy Markdown

@canicefavour Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Cedarich

Copy link
Copy Markdown
Contributor

Kindly fix CI

@canicefavour

Copy link
Copy Markdown
Author

Has been fixed

@Cedarich

Cedarich commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

@canicefavour

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.

Mobile: Add network-aware retry and backoff to the API client

2 participants