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

  1. Check API availability/health and recent deploys; this usually means the endpoint was unreachable across all retries
  2. Increase MAX_RETRIES or backoff ceiling if transient outages are common in your environment
  3. Log the __typename of each failed attempt to detect unhandled response types and add branches for them
  4. 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

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.