moeru-ai/airi · error · Error
Auth request failed (${error.status ?? 'unknown'})
Error message
Auth request failed (${error.status ?? 'unknown'}) What it means
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.
Source
Thrown at apps/ui-server-auth/src/modules/profile.ts:94
}
/**
* Read the current session via the typed better-auth client.
*
* Use when:
* - Bootstrapping the profile page; decides whether to render the form or
* bounce the user to the sign-in page.
*
* Returns:
* - `user: null` for unauthenticated requests (better-auth client returns
* `null` data, not an error, in that case).
* - {@link CurrentSessionResult} with the trimmed user fields otherwise.
*/
export async function getCurrentSession(args: AuthFetchBase): Promise<CurrentSessionResult> {
const client = getAuthClient(args)
const { data, error } = await client.getSession()
if (error)
throw new Error(error.message ?? `Auth request failed (${error.status ?? 'unknown'})`)
if (!data?.user)
return { user: null }
return {
user: {
id: data.user.id,
name: data.user.name,
email: data.user.email,
emailVerified: data.user.emailVerified,
image: data.user.image ?? null,
createdAt: toIsoString(data.user.createdAt),
},
}
}
/**
* Update the signed-in user's display name and/or avatar.
*View on GitHub (pinned to 27111382b4)
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.
Defensive patterns
Strategy: try-catch
Try / catch
try {
const { user } = await getCurrentSession(args)
if (!user) // redirect to sign-in
} catch (e) {
// real request failure (server down / network) — show retry, do NOT treat as logged out
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- signOut failed
- updateUser failed
- changePassword failed
- Auth request failed (${response.status})
- Unexpected response
AI-assisted analysis of moeru-ai/airi@27111382b4 (2026-08-12).
Data as JSON: /api/errors/7075df1dd872f7ec.
Report an issue: GitHub.