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
This commit is contained in:
@@ -217,25 +217,39 @@ export async function getBridgeSession(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const url = `${opts?.baseUrl ?? getOauthConfig().BASE_API_URL}/v1/sessions/${sessionId}`
|
const url = `${opts?.baseUrl ?? getOauthConfig().BASE_API_URL}/v1/sessions/${sessionId}`
|
||||||
|
const timeoutMs = 10_000
|
||||||
logForDebugging(`[bridge] Fetching session ${sessionId}`)
|
logForDebugging(`[bridge] Fetching session ${sessionId}`)
|
||||||
|
|
||||||
let response
|
let response
|
||||||
try {
|
try {
|
||||||
response = await axios.get<{ environment_id?: string; title?: string }>(
|
response = await axios.get<{ environment_id?: string; title?: string }>(
|
||||||
url,
|
url,
|
||||||
{ headers, timeout: 10_000, validateStatus: s => s < 500 },
|
{ headers, timeout: timeoutMs, validateStatus: s => s < 500 },
|
||||||
)
|
)
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
|
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(
|
logForDebugging(
|
||||||
`[bridge] Session fetch request failed: ${errorMessage(err)}`,
|
`[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
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
const detail = extractErrorDetail(response.data)
|
const detail = extractErrorDetail(response.data)
|
||||||
logForDebugging(
|
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
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,9 +116,21 @@ async function fetchBootstrapAPI(): Promise<BootstrapResponse | null> {
|
|||||||
return parsed.data
|
return parsed.data
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
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(
|
logForDebugging(
|
||||||
`[Bootstrap] Fetch failed: ${axios.isAxiosError(error) ? (error.response?.status ?? error.code) : 'unknown'}`,
|
`[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
|
throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user