slymnoyann/hey-1 · error · Error
Unknown error during token refresh
Error message
Unknown error during token refresh
What it means
Thrown after all MAX_RETRIES attempts of executeTokenRefresh complete without producing tokens and without hitting the ForbiddenError branch. Each failure path that is not a definitive rejection exhausts exponential-backoff retries (1s, 2s, ...), and the loop ends with this catch-all error, clearing the shared refreshPromise in finally.
Source
Thrown at src/helpers/tokenManager.ts:52
refreshToken: newRefreshToken
});
return newAccessToken;
}
if (refreshResult.__typename === "ForbiddenError") {
signOut();
throw new Error("Refresh token is invalid or expired");
}
if (attempt < MAX_RETRIES - 1) {
await new Promise((resolve) =>
setTimeout(resolve, 2 ** attempt * 1000)
);
}
}
throw new Error("Unknown error during token refresh");
} finally {
refreshPromise = null;
}
};
export const refreshTokens = (refreshToken: string): Promise<string> => {
if (!refreshPromise) {
refreshPromise = executeTokenRefresh(refreshToken);
}
return refreshPromise;
};
export const isTokenExpiringSoon = (accessToken: string | null): boolean => {
if (!accessToken) {
return false;
}
View on GitHub (pinned to 88c8f9d553)
Solutions
- Check API availability/health and recent deploys; this usually means the endpoint was unreachable across all retries
- Increase MAX_RETRIES or backoff ceiling if transient outages are common in your environment
- Log the __typename of each failed attempt to detect unhandled response types and add branches for them
- Catch this error globally and signOut() or queue the refresh for later when connectivity returns
Example fix
// before
throw new Error("Unknown error during token refresh");
// after
console.error(`Token refresh failed after ${MAX_RETRIES} attempts`);
throw new Error("Unknown error during token refresh"); Defensive patterns
Strategy: retry
Validate before calling
if (typeof navigator !== "undefined" && !navigator.onLine) {
// defer refresh until connectivity returns instead of burning retries
window.addEventListener("online", () => refreshTokens(refreshToken), { once: true });
return;
} Type guard
// no type guard applies; failure is exhaustion of retries across unknown response shapes null
Try / catch
try {
await refreshTokens(refreshToken);
} catch (e) {
if (e instanceof Error && e.message === "Unknown error during token refresh") {
signOut(); // or schedule a deferred refresh
window.location.href = "/login";
}
throw e;
} Prevention
- Gate refresh attempts on connectivity to preserve retries for real failures
- Monitor API health; this error usually coincides with outages or deploys
- Log the __typename of each attempt to catch unhandled response variants early
When it happens
Trigger: Sustained network failures or 5xx responses across every retry attempt; the server repeatedly returning unexpected __typename values; or the mutation resolving with a truthy refreshResult that matches none of the handled typenames on every attempt.
Common situations: API server down or restarting during a deploy, prolonged offline state, load balancer returning HTML error pages that parse into unexpected shapes, or a schema change introducing a new typename the client does not handle.
Related errors
AI-assisted analysis of slymnoyann/hey-1@88c8f9d553 (2026-08-28).
Data as JSON: /api/errors/7859fb994c4e113f.
Report an issue: GitHub.