MCPcopy Index your code
hub / github.com/codeaashu/claude-code / fetchSessionLogsFromUrl

Function fetchSessionLogsFromUrl

src/services/api/sessionIngress.ts:420–485  ·  view source on GitHub ↗

* Shared implementation for fetching session logs from a URL

(
  sessionId: string,
  url: string,
  headers: Record<string, string>,
)

Source from the content-addressed store, hash-verified

418 * Shared implementation for fetching session logs from a URL
419 */
420async function fetchSessionLogsFromUrl(
421 sessionId: string,
422 url: string,
423 headers: Record<string, string>,
424): Promise<Entry[] | null> {
425 try {
426 const response = await axios.get(url, {
427 headers,
428 timeout: 20000,
429 validateStatus: status => status < 500,
430 params: isEnvTruthy(process.env.CLAUDE_AFTER_LAST_COMPACT)
431 ? { after_last_compact: true }
432 : undefined,
433 })
434
435 if (response.status === 200) {
436 const data = response.data
437
438 // Validate the response structure
439 if (!data || typeof data !== 'object' || !Array.isArray(data.loglines)) {
440 logError(
441 new Error(
442 `Invalid session logs response format: ${jsonStringify(data)}`,
443 ),
444 )
445 logForDiagnosticsNoPII('error', 'session_get_fail_invalid_response')
446 return null
447 }
448
449 const logs = data.loglines as Entry[]
450 logForDebugging(
451 `Fetched ${logs.length} session logs for session ${sessionId}`,
452 )
453 return logs
454 }
455
456 if (response.status === 404) {
457 logForDebugging(`No existing logs for session ${sessionId}`)
458 logForDiagnosticsNoPII('warn', 'session_get_no_logs_for_session')
459 return []
460 }
461
462 if (response.status === 401) {
463 logForDebugging('Auth token expired or invalid')
464 logForDiagnosticsNoPII('error', 'session_get_fail_bad_token')
465 throw new Error(
466 'Your session has expired. Please run /login to sign in again.',
467 )
468 }
469
470 logForDebugging(
471 `Failed to fetch session logs: ${response.status} ${response.statusText}`,
472 )
473 logForDiagnosticsNoPII('error', 'session_get_fail_status', {
474 status: response.status,
475 })
476 return null
477 } catch (error) {

Callers 3

appendSessionLogImplFunction · 0.85
getSessionLogsFunction · 0.85
getSessionLogsViaOAuthFunction · 0.85

Calls 6

isEnvTruthyFunction · 0.85
jsonStringifyFunction · 0.85
logForDiagnosticsNoPIIFunction · 0.85
logForDebuggingFunction · 0.85
getMethod · 0.65
logErrorFunction · 0.50

Tested by

no test coverage detected