MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / doFetch

Function doFetch

source code/utils/fastMode.ts:463–530  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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