MCPcopy Create free account
hub / github.com/Noumena-Network/code / doFetch

Function doFetch

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

Source from the content-addressed store, hash-verified

455 }
456
457 async function doFetch(): Promise<void> {
458 try {
459 let status: FastModeResponse
460 try {
461 status = await fetchWithCurrentAuth()
462 } catch (err) {
463 const isAuthError =
464 axios.isAxiosError(err) &&
465 (err.response?.status === 401 ||
466 (err.response?.status === 403 &&
467 typeof err.response?.data === 'string' &&
468 err.response.data.includes('OAuth token has been revoked')))
469 if (isAuthError) {
470 const failedSession = authRuntime.getCurrentSession()
471 if (
472 failedSession.headersKind === 'bearer' &&
473 failedSession.accessToken
474 ) {
475 const refreshedSession = await authRuntime.resolveSession({
476 allowRefresh: true,
477 forceRefresh: true,
478 })
479 const refreshedAuth = resolveFastModeFetchAuth(refreshedSession)
480 if (refreshedAuth && 'accessToken' in refreshedAuth) {
481 status = await fetchFastModeStatus(refreshedAuth)
482 } else {
483 throw err
484 }
485 } else {
486 throw err
487 }
488 } else {
489 throw err
490 }
491 }
492
493 const previousEnabled =
494 orgStatus.status !== 'pending'
495 ? orgStatus.status === 'enabled'
496 : getGlobalConfig().penguinModeOrgEnabled
497 orgStatus = status.enabled
498 ? { status: 'enabled' }
499 : {
500 status: 'disabled',
501 reason: status.disabled_reason ?? 'preference',
502 }
503 if (previousEnabled !== status.enabled) {
504 // When org disables fast mode, permanently turn off the user's fast mode setting
505 if (!status.enabled) {
506 updateSettingsForSource('userSettings', { fastMode: undefined })
507 }
508 saveGlobalConfig(current => ({
509 ...current,
510 penguinModeOrgEnabled: status.enabled,
511 }))
512 orgFastModeChange.emit(status.enabled)
513 }
514 logForDebugging(

Callers 1

prefetchFastModeStatusFunction · 0.85

Calls 12

fetchWithCurrentAuthFunction · 0.85
resolveFastModeFetchAuthFunction · 0.85
fetchFastModeStatusFunction · 0.85
isInternalBuildFunction · 0.85
emitMethod · 0.80
getGlobalConfigFunction · 0.70
saveGlobalConfigFunction · 0.70
logForDebuggingFunction · 0.70
getCurrentSessionMethod · 0.65
resolveSessionMethod · 0.65
updateSettingsForSourceFunction · 0.50
logEventFunction · 0.50

Tested by

no test coverage detected