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

Function withOAuth401Retry

src/utils/http.ts:115–136  ·  view source on GitHub ↗
(
  request: () => Promise<T>,
  opts?: { also403Revoked?: boolean },
)

Source from the content-addressed store, hash-verified

113 * revoked" body (some endpoints signal revocation this way instead of 401).
114 */
115export async function withOAuth401Retry<T>(
116 request: () => Promise<T>,
117 opts?: { also403Revoked?: boolean },
118): Promise<T> {
119 try {
120 return await request()
121 } catch (err) {
122 if (!axios.isAxiosError(err)) throw err
123 const status = err.response?.status
124 const isAuthError =
125 status === 401 ||
126 (opts?.also403Revoked &&
127 status === 403 &&
128 typeof err.response?.data === 'string' &&
129 err.response.data.includes('OAuth token has been revoked'))
130 if (!isAuthError) throw err
131 const failedAccessToken = getClaudeAIOAuthTokens()?.accessToken
132 if (!failedAccessToken) throw err
133 await handleOAuth401Error(failedAccessToken)
134 return await request()
135 }
136}

Callers 5

grove.tsFile · 0.85
markGroveNoticeViewedFunction · 0.85
updateGroveSettingsFunction · 0.85
fetchBootstrapAPIFunction · 0.85
_checkMetricsEnabledAPIFunction · 0.85

Calls 1

handleOAuth401ErrorFunction · 0.85

Tested by

no test coverage detected