{"record":{"id":"7075df1dd872f7ec","repo":"moeru-ai/airi","slug":"auth-request-failed-error-status-unknown","errorCode":null,"errorMessage":"Auth request failed (${error.status ?? 'unknown'})","messagePattern":"Auth request failed \\((.+?)\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/ui-server-auth/src/modules/profile.ts","lineNumber":94,"sourceCode":"}\n\n/**\n * Read the current session via the typed better-auth client.\n *\n * Use when:\n * - Bootstrapping the profile page; decides whether to render the form or\n *   bounce the user to the sign-in page.\n *\n * Returns:\n * - `user: null` for unauthenticated requests (better-auth client returns\n *   `null` data, not an error, in that case).\n * - {@link CurrentSessionResult} with the trimmed user fields otherwise.\n */\nexport async function getCurrentSession(args: AuthFetchBase): Promise<CurrentSessionResult> {\n  const client = getAuthClient(args)\n  const { data, error } = await client.getSession()\n  if (error)\n    throw new Error(error.message ?? `Auth request failed (${error.status ?? 'unknown'})`)\n  if (!data?.user)\n    return { user: null }\n\n  return {\n    user: {\n      id: data.user.id,\n      name: data.user.name,\n      email: data.user.email,\n      emailVerified: data.user.emailVerified,\n      image: data.user.image ?? null,\n      createdAt: toIsoString(data.user.createdAt),\n    },\n  }\n}\n\n/**\n * Update the signed-in user's display name and/or avatar.\n *","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/moeru-ai/airi/blob/27111382b4a79a7e983289d6e983a06af185ed0f/apps/ui-server-auth/src/modules/profile.ts#L76-L112","documentation":"Thrown by getCurrentSession when the typed better-auth client's getSession() returns an error object. The message prefers error.message and falls back to a status string ('unknown' if status is missing). Note: a missing session returns { user: null }, not an error — this throw only fires on an actual transport/server error, not on being logged out.","triggerScenarios":"The better-auth server returns a 500 from /get-session; a network failure surfaces as an error object; the auth client base URL is wrong so the request errors; the server schema changed and the client cannot parse the response.","commonSituations":"Auth backend down during profile page load; apiServerUrl mispointed; version drift between the better-auth client and server breaking the response contract; cookie/CORS issues causing the fetch to fail.","solutions":["Distinguish this from 'logged out': logged out yields { user: null } cleanly; this throw means a real request failure.","Check error.status — 5xx indicates server fault, missing status usually means network/CORS.","Verify apiServerUrl and that the auth service is reachable.","Catch in the profile bootstrap and show a retry rather than treating it as unauthenticated."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const { user } = await getCurrentSession(args)\n  if (!user) // redirect to sign-in\n} catch (e) {\n  // real request failure (server down / network) — show retry, do NOT treat as logged out\n}","preventionTips":["Distinguish the throw (transport/server error) from { user: null } (cleanly logged out).","On the profile bootstrap, retry once on transient errors before failing.","Verify apiServerUrl and auth service health."],"tags":["auth","profile","better-auth","session","ui-server-auth"],"backgroundTag":null,"analyzedSha":"27111382b4a79a7e983289d6e983a06af185ed0f","analyzedAt":"2026-08-12T18:33:34.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}