From df2b9f2b7b4c661ee3d9ed5dc58b3064de0599d1 Mon Sep 17 00:00:00 2001 From: muhnehh <86887033+muhnehh@users.noreply.github.com> Date: Mon, 13 Apr 2026 17:17:12 +0400 Subject: [PATCH] fix: improve fetch diagnostics for bootstrap and session requests (#646) * fix: improve fetch diagnostics for bootstrap and session requests * chore: derive session timeout from shared constant --- src/bridge/createSession.ts | 24 +++++++++++++++++++----- src/services/api/bootstrap.ts | 18 +++++++++++++++--- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/bridge/createSession.ts b/src/bridge/createSession.ts index d5bc83ac..b1c787ed 100644 --- a/src/bridge/createSession.ts +++ b/src/bridge/createSession.ts @@ -217,25 +217,39 @@ export async function getBridgeSession( } const url = `${opts?.baseUrl ?? getOauthConfig().BASE_API_URL}/v1/sessions/${sessionId}` + const timeoutMs = 10_000 logForDebugging(`[bridge] Fetching session ${sessionId}`) let response try { response = await axios.get<{ environment_id?: string; title?: string }>( url, - { headers, timeout: 10_000, validateStatus: s => s < 500 }, + { headers, timeout: timeoutMs, validateStatus: s => s < 500 }, ) } catch (err: unknown) { - logForDebugging( - `[bridge] Session fetch request failed: ${errorMessage(err)}`, - ) + if (axios.isAxiosError(err)) { + const status = err.response?.status ?? 'no-response' + const code = err.code ?? 'unknown-code' + const requestUrl = err.config?.url ?? url + const method = err.config?.method?.toUpperCase() ?? 'GET' + const message = err.message ?? errorMessage(err) + const timeout = err.config?.timeout ?? timeoutMs + + logForDebugging( + `[bridge] Session fetch request failed: status=${status} code=${code} method=${method} url=${requestUrl} timeout=${timeout} message=${message}`, + ) + } else { + logForDebugging( + `[bridge] Session fetch request failed: url=${url} timeout=${timeoutMs} message=${errorMessage(err)}`, + ) + } return null } if (response.status !== 200) { const detail = extractErrorDetail(response.data) logForDebugging( - `[bridge] Session fetch failed with status ${response.status}${detail ? `: ${detail}` : ''}`, + `[bridge] Session fetch failed with status ${response.status} url=${url}${detail ? `: ${detail}` : ''}`, ) return null } diff --git a/src/services/api/bootstrap.ts b/src/services/api/bootstrap.ts index c11f6ca4..8e5d4b4d 100644 --- a/src/services/api/bootstrap.ts +++ b/src/services/api/bootstrap.ts @@ -116,9 +116,21 @@ async function fetchBootstrapAPI(): Promise { return parsed.data }) } catch (error) { - logForDebugging( - `[Bootstrap] Fetch failed: ${axios.isAxiosError(error) ? (error.response?.status ?? error.code) : 'unknown'}`, - ) + if (axios.isAxiosError(error)) { + const status = error.response?.status ?? 'no-response' + const code = error.code ?? 'unknown-code' + const method = error.config?.method?.toUpperCase() ?? 'UNKNOWN' + const requestUrl = error.config?.url ?? 'unknown-url' + const message = error.message ?? 'unknown axios error' + + logForDebugging( + `[Bootstrap] Fetch failed: status=${status} code=${code} method=${method} url=${requestUrl} message=${message}`, + ) + } else { + const message = error instanceof Error ? error.message : String(error) + logForDebugging(`[Bootstrap] Fetch failed: ${message}`) + } + throw error } }