From 186dc208bea5c20ffe7e3e563c31b71d5552f1a2 Mon Sep 17 00:00:00 2001 From: AliReza Date: Sun, 11 Oct 2026 22:54:21 +0330 Subject: [PATCH] GET requests time out after 8s (was 15s): the 'internet is slow' message and retry come sooner Writes keep 15s so an early cut does not make the user submit twice. Worst-case boot wait with an unreachable API goes from ~50s to ~27s (3 attempts + backoff). Not tested on a real slow network. Co-Authored-By: Claude Sonnet 5.5 --- src/api/http.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/api/http.ts b/src/api/http.ts index 8f9addb..bc8a281 100644 --- a/src/api/http.ts +++ b/src/api/http.ts @@ -77,6 +77,7 @@ export interface HttpClientOptions { baseUrl: string; storage?: TokenStorage; timeoutMs?: number; + readTimeoutMs?: number; maxRetries?: number; } @@ -163,6 +164,9 @@ export function createHttpClient(options: HttpClientOptions) { const baseUrl = options.baseUrl.replace(/\/+$/, ''); const storage = options.storage ?? localTokenStorage; const defaultTimeout = options.timeoutMs ?? 15_000; + // خواندن‌ها (GET) تکرارپذیرند و کاربر پشتِ اسپلش منتظر است: ۸ ثانیه کافی است، بعدش تلاشِ دوباره یا پیامِ «اینترنت کند است». + // نوشتن‌ها (POST/PATCH) همان ۱۵ می‌مانند: قطعِ زودهنگام یعنی کاربر دوباره می‌زند و ممکن است ثبتِ دوباره شود. + const readTimeout = options.readTimeoutMs ?? 8_000; const maxRetries = options.maxRetries ?? 2; const inFlight = new Map>(); @@ -237,7 +241,7 @@ export function createHttpClient(options: HttpClientOptions) { if (body !== undefined) headers['Content-Type'] = 'application/json'; if (opts.idempotencyKey) headers['Idempotency-Key'] = opts.idempotencyKey; - const timer = timeoutSignal(opts.timeoutMs ?? defaultTimeout); + const timer = timeoutSignal(opts.timeoutMs ?? (method === 'GET' ? readTimeout : defaultTimeout)); try { return await fetch(`${baseUrl}${path}`, { method,