MCPcopy
hub / github.com/codeaashu/claude-code / doFetch

Function doFetch

src/utils/fastMode.ts:461–528  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

459 }
460
461 async function doFetch(): Promise<void> {
462 try {
463 let status: FastModeResponse
464 try {
465 status = await fetchWithCurrentAuth()
466 } catch (err) {
467 const isAuthError =
468 axios.isAxiosError(err) &&
469 (err.response?.status === 401 ||
470 (err.response?.status === 403 &&
471 typeof err.response?.data === 'string' &&
472 err.response.data.includes('OAuth token has been revoked')))
473 if (isAuthError) {
474 const failedAccessToken = getClaudeAIOAuthTokens()?.accessToken
475 if (failedAccessToken) {
476 await handleOAuth401Error(failedAccessToken)
477 status = await fetchWithCurrentAuth()
478 } else {
479 throw err
480 }
481 } else {
482 throw err
483 }
484 }
485
486 const previousEnabled =
487 orgStatus.status !== 'pending'
488 ? orgStatus.status === 'enabled'
489 : getGlobalConfig().penguinModeOrgEnabled
490 orgStatus = status.enabled
491 ? { status: 'enabled' }
492 : {
493 status: 'disabled',
494 reason: status.disabled_reason ?? 'preference',
495 }
496 if (previousEnabled !== status.enabled) {
497 // When org disables fast mode, permanently turn off the user's fast mode setting
498 if (!status.enabled) {
499 updateSettingsForSource('userSettings', { fastMode: undefined })
500 }
501 saveGlobalConfig(current => ({
502 ...current,
503 penguinModeOrgEnabled: status.enabled,
504 }))
505 orgFastModeChange.emit(status.enabled)
506 }
507 logForDebugging(
508 `Org fast mode: ${status.enabled ? 'enabled' : `disabled (${status.disabled_reason ?? 'preference'})`}`,
509 )
510 } catch (err) {
511 // On failure: ants default to enabled (don't block internal users).
512 // External users: fall back to the cached penguinModeOrgEnabled value;
513 // if no positive cache, disable with network_error reason.
514 const isAnt = process.env.USER_TYPE === 'ant'
515 const cachedEnabled = getGlobalConfig().penguinModeOrgEnabled === true
516 orgStatus =
517 isAnt || cachedEnabled
518 ? { status: 'enabled' }

Callers 1

prefetchFastModeStatusFunction · 0.85

Calls 8

fetchWithCurrentAuthFunction · 0.85
handleOAuth401ErrorFunction · 0.85
getGlobalConfigFunction · 0.85
updateSettingsForSourceFunction · 0.85
saveGlobalConfigFunction · 0.85
logForDebuggingFunction · 0.85
logEventFunction · 0.85
emitMethod · 0.80

Tested by

no test coverage detected