QuantumNous/new-api · error · Error
Request failed
Error message
Request failed
What it means
Thrown by getFreshAuthHeaders when a token refresh was needed (access token missing or expiring within 60s), the refresh attempt ended as outcome.kind 'transient_error', and no still-valid token exists in the store. 'Request failed' (i18n key) means the refresh could not complete due to a network/transport problem, not an auth rejection; the original error is attached as { cause }.
Source
Thrown at web/src/lib/auth-session.ts:417
return getCommonHeaders()
}
const outcome = await refreshAuthentication()
if (outcome.kind === 'authenticated') {
return getCommonHeaders()
}
const current = useAuthStore.getState().auth
if (
current.accessToken &&
current.accessExpiresAt &&
current.accessExpiresAt > Math.floor(Date.now() / 1000)
) {
return getCommonHeaders()
}
if (outcome.kind === 'transient_error') {
throw new Error(t('Request failed'), { cause: outcome.error })
}
throw new Error(t('Session expired!'))
}
View on GitHub (pinned to e2c7aa7b10)
Solutions
- Retry the originating request after connectivity returns — inspect error.cause to confirm it is a network-level failure (TypeError: Failed to fetch, ECONNRESET-equivalent).
- Check whether the backend session/refresh endpoint is up (curl it) and whether a deploy was in progress.
- Add bounded retry with backoff around getFreshAuthHeaders for transient_error outcomes so momentary outages self-heal.
- If it persists, capture outcome.error details — a misclassified non-transient failure masquerading as transient is a bug in refreshAuthentication's classification.
Example fix
// caller-side bounded retry for transient refresh failures
async function withFreshHeaders(retries = 2): Promise<Record<string, string>> {
try {
return await getFreshAuthHeaders()
} catch (error) {
if (retries > 0 && error.cause !== undefined && navigator.onLine) {
await new Promise((r) => setTimeout(r, 1000))
return withFreshHeaders(retries - 1)
}
throw error
}
} Defensive patterns
Strategy: retry
Validate before calling
if (!navigator.onLine) {
// skip the request now; queue it until connectivity returns instead of eating a transient_error
} Try / catch
try {
headers = await getFreshAuthHeaders()
} catch (error) {
if (/Request failed/i.test(error.message)) {
// inspect error.cause; retry with backoff when offline/5xx, abort on hard failures
}
} Prevention
- Wrap getFreshAuthHeaders in a bounded retry (2 attempts, exponential backoff) for transient outcomes
- Refresh tokens proactively (the 60s refreshBefore window) so requests rarely need a live refresh to succeed
When it happens
Trigger: refreshAuthentication() returns {kind:'transient_error'} — offline, DNS failure, connection reset, 5xx from the session endpoint — while auth.accessExpiresAt is already past, so no cached token can serve the request.
Common situations: Brief network drop or backend restart exactly when the access token expired; mobile/flaky connections; proxy timeouts on the refresh endpoint during deploys.
Related errors
- Failed to load API keys
- Invalid authentication rotation response
- Authentication rotation has no active session
- Authentication rotation session mismatch
- Session expired!
AI-assisted analysis of QuantumNous/new-api@e2c7aa7b10 (2026-08-15).
Data as JSON: /api/errors/7470730d90b1637a.
Report an issue: GitHub.