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

Function doFetch

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

Source from the content-addressed store, hash-verified

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

Callers 1

prefetchFastModeStatusFunction · 0.85

Calls 8

fetchWithCurrentAuthFunction · 0.85
handleOAuth401ErrorFunction · 0.85
getGlobalConfigFunction · 0.85
updateSettingsForSourceFunction · 0.85
saveGlobalConfigFunction · 0.85
logEventFunction · 0.85
logForDebuggingFunction · 0.70
emitMethod · 0.45

Tested by

no test coverage detected