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 <noreply@anthropic.com>
This commit is contained in:
@@ -77,6 +77,7 @@ export interface HttpClientOptions {
|
|||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
storage?: TokenStorage;
|
storage?: TokenStorage;
|
||||||
timeoutMs?: number;
|
timeoutMs?: number;
|
||||||
|
readTimeoutMs?: number;
|
||||||
maxRetries?: number;
|
maxRetries?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,6 +164,9 @@ export function createHttpClient(options: HttpClientOptions) {
|
|||||||
const baseUrl = options.baseUrl.replace(/\/+$/, '');
|
const baseUrl = options.baseUrl.replace(/\/+$/, '');
|
||||||
const storage = options.storage ?? localTokenStorage;
|
const storage = options.storage ?? localTokenStorage;
|
||||||
const defaultTimeout = options.timeoutMs ?? 15_000;
|
const defaultTimeout = options.timeoutMs ?? 15_000;
|
||||||
|
// خواندنها (GET) تکرارپذیرند و کاربر پشتِ اسپلش منتظر است: ۸ ثانیه کافی است، بعدش تلاشِ دوباره یا پیامِ «اینترنت کند است».
|
||||||
|
// نوشتنها (POST/PATCH) همان ۱۵ میمانند: قطعِ زودهنگام یعنی کاربر دوباره میزند و ممکن است ثبتِ دوباره شود.
|
||||||
|
const readTimeout = options.readTimeoutMs ?? 8_000;
|
||||||
const maxRetries = options.maxRetries ?? 2;
|
const maxRetries = options.maxRetries ?? 2;
|
||||||
|
|
||||||
const inFlight = new Map<string, Promise<unknown>>();
|
const inFlight = new Map<string, Promise<unknown>>();
|
||||||
@@ -237,7 +241,7 @@ export function createHttpClient(options: HttpClientOptions) {
|
|||||||
if (body !== undefined) headers['Content-Type'] = 'application/json';
|
if (body !== undefined) headers['Content-Type'] = 'application/json';
|
||||||
if (opts.idempotencyKey) headers['Idempotency-Key'] = opts.idempotencyKey;
|
if (opts.idempotencyKey) headers['Idempotency-Key'] = opts.idempotencyKey;
|
||||||
|
|
||||||
const timer = timeoutSignal(opts.timeoutMs ?? defaultTimeout);
|
const timer = timeoutSignal(opts.timeoutMs ?? (method === 'GET' ? readTimeout : defaultTimeout));
|
||||||
try {
|
try {
|
||||||
return await fetch(`${baseUrl}${path}`, {
|
return await fetch(`${baseUrl}${path}`, {
|
||||||
method,
|
method,
|
||||||
|
|||||||
Reference in New Issue
Block a user