add shared request timeout and AbortSignal cancellation support - #1383
Open
canicefavour wants to merge 2 commits into
Open
canicefavour wants to merge 2 commits into
canicefavour wants to merge 2 commits into
Conversation
|
@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! 🚀 |
Contributor
|
Kindly fix CI |
Author
|
Has been fixed |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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