fix: surface codex account auth errors (#3510)

This commit is contained in:
Jinjing
2026-05-30 00:07:22 -07:00
committed by GitHub
parent 504b98d873
commit 6b8a2b6b26
7 changed files with 397 additions and 16 deletions
+37
View File
@@ -0,0 +1,37 @@
const CODEX_AUTH_ERROR_PATTERNS = [
/access token could not be refreshed/i,
/authentication session could not be refreshed/i,
/refresh token (?:has expired|was already used|was revoked)/i,
/you have since logged out or signed in to another account/i,
/please (?:log out and )?sign in again/i,
/please reauthenticate/i,
/not logged in/i,
/token data is not available/i,
/auth (?:is missing|tokens are missing|does not expose)/i
]
const ANSI_ESCAPE_RE = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*[a-zA-Z]`, 'g')
export function isCodexAuthError(error: string | null | undefined): boolean {
const message = error?.trim()
if (!message) {
return false
}
return CODEX_AUTH_ERROR_PATTERNS.some((pattern) => pattern.test(message))
}
export function extractCodexAuthError(output: string | null | undefined): string | null {
const cleanOutput = output?.replace(ANSI_ESCAPE_RE, '').trim()
if (!cleanOutput) {
return null
}
const matchingLine = cleanOutput
.split(/\r?\n/)
.map((line) => line.trim())
.find(isCodexAuthError)
if (matchingLine) {
return matchingLine
}
return isCodexAuthError(cleanOutput) ? cleanOutput.slice(0, 4_000) : null
}