{"record":{"id":"7859fb994c4e113f","repo":"slymnoyann/hey-1","slug":"unknown-error-during-token-refresh","errorCode":null,"errorMessage":"Unknown error during token refresh","messagePattern":"Unknown error during token refresh","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/helpers/tokenManager.ts","lineNumber":52,"sourceCode":"          refreshToken: newRefreshToken\n        });\n\n        return newAccessToken;\n      }\n\n      if (refreshResult.__typename === \"ForbiddenError\") {\n        signOut();\n        throw new Error(\"Refresh token is invalid or expired\");\n      }\n\n      if (attempt < MAX_RETRIES - 1) {\n        await new Promise((resolve) =>\n          setTimeout(resolve, 2 ** attempt * 1000)\n        );\n      }\n    }\n\n    throw new Error(\"Unknown error during token refresh\");\n  } finally {\n    refreshPromise = null;\n  }\n};\n\nexport const refreshTokens = (refreshToken: string): Promise<string> => {\n  if (!refreshPromise) {\n    refreshPromise = executeTokenRefresh(refreshToken);\n  }\n\n  return refreshPromise;\n};\n\nexport const isTokenExpiringSoon = (accessToken: string | null): boolean => {\n  if (!accessToken) {\n    return false;\n  }\n","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/slymnoyann/hey-1/blob/88c8f9d55340d57a37846ff72f55c2c604e3a566/src/helpers/tokenManager.ts#L34-L70","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nthrow new Error(\"Unknown error during token refresh\");\n\n// after\nconsole.error(`Token refresh failed after ${MAX_RETRIES} attempts`);\nthrow new Error(\"Unknown error during token refresh\");","handlingStrategy":"retry","validationCode":"if (typeof navigator !== \"undefined\" && !navigator.onLine) {\n  // defer refresh until connectivity returns instead of burning retries\n  window.addEventListener(\"online\", () => refreshTokens(refreshToken), { once: true });\n  return;\n}","typeGuard":"// no type guard applies; failure is exhaustion of retries across unknown response shapes\nnull","tryCatchPattern":"try {\n  await refreshTokens(refreshToken);\n} catch (e) {\n  if (e instanceof Error && e.message === \"Unknown error during token refresh\") {\n    signOut(); // or schedule a deferred refresh\n    window.location.href = \"/login\";\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["authentication","retry","network","token-refresh","exhausted-retries"],"backgroundTag":"token-refresh-retry-exhausted","analyzedSha":"88c8f9d55340d57a37846ff72f55c2c604e3a566","analyzedAt":"2026-08-28T16:20:43.640Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}