{"record":{"id":"cd3131b52e45aa27","repo":"gitbutlerapp/gitbutler","slug":"login-token-expired-please-log-in-to-gitbutler-ag","errorCode":null,"errorMessage":"Login token expired. Please log in to GitButler again.","messagePattern":"Login token expired\\. Please log in to GitButler again\\.","errorType":"http","errorClass":"ApiError","httpStatus":401,"severity":"error","filePath":"packages/shared/src/lib/network/httpClient.ts","lineNumber":114,"sourceCode":"\n\tasync patch<T>(path: string, opts?: RequestOptions) {\n\t\treturn await this.requestJson<T>(path, { ...opts, method: \"PATCH\" });\n\t}\n\n\tasync delete<T>(path: string, opts?: RequestOptions) {\n\t\treturn await this.requestJson<T>(path, { ...opts, method: \"DELETE\" });\n\t}\n\n\tasync postRaw(path: string, opts?: RequestOptions) {\n\t\treturn await this.request(path, { ...opts, method: \"POST\" });\n\t}\n}\n\nasync function parseResponseJSON(response: Response) {\n\tif (response.status === 204 || response.status === 205) {\n\t\treturn null;\n\t} else if (response.status === 401) {\n\t\tthrow new ApiError(\"Login token expired. Please log in to GitButler again.\", response);\n\t} else if (response.status >= 400) {\n\t\tconst text = await response.text();\n\t\tif (text.includes(\"401 Unauthorized\") || text.includes(\"401 unauthorized\")) {\n\t\t\tthrow new ApiError(\"Login token expired. Please log in to GitButler again.\", response);\n\t\t}\n\t\tthrow new ApiError(`HTTP Error ${response.statusText}: ${text}`, response);\n\t} else {\n\t\treturn await response.json();\n\t}\n}\n\nfunction formatBody(body?: FormData | object) {\n\tif (!body) return;\n\treturn body instanceof FormData ? body : JSON.stringify(body);\n}\n","sourceCodeStart":96,"sourceCodeEnd":130,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/packages/shared/src/lib/network/httpClient.ts#L96-L130","documentation":"parseResponseJSON in HttpClient maps any HTTP 401 response to an ApiError with the fixed message \"Login token expired. Please log in to GitButler again.\" The library throws this because a 401 from the GitButler backend universally means the stored auth token is no longer accepted, and callers should prompt re-authentication.","triggerScenarios":"Any HttpClient get/post/put/patch/delete (via requestJson) receiving a response with status exactly 401 — e.g. the X-Auth-Token header is missing, expired, or revoked server-side.","commonSituations":"User session expired after inactivity; server-side token rotation invalidated the stored token; clock skew; logging in from another device that invalidated the session; backend restarted with ephemeral session store.","solutions":["Catch the ApiError in the UI and route the user to the login flow (loginWithEmail) to obtain a fresh token","Clear/refresh the stored token and retry after re-authentication","Check the token store feeding HttpClient's `token` Readable is actually set before requests","If 401 happens immediately after login, verify the backend session endpoint and X-Auth-Token header wiring"],"exampleFix":"// before\nconst data = await httpClient.get(`projects/${projectId}`);\n// after\ntry {\n  const data = await httpClient.get(`projects/${projectId}`);\n} catch (e) {\n  if (e instanceof ApiError && e.response?.status === 401) {\n    uiStore.setNeedsAuth(true); // prompt re-login\n    return;\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"const token = get(tokenStore);\nif (!token) {\n  await promptRelogin(); // avoid firing requests without a token\n  return;\n}","typeGuard":"function isAuthError(e: unknown): e is ApiError {\n  return e instanceof ApiError && e.response?.status === 401;\n}","tryCatchPattern":"try {\n  await httpClient.get(path);\n} catch (e) {\n  if (e instanceof ApiError && e.message.includes('Login token expired')) {\n    await loginService.loginWithEmail(email, password); // re-auth then retry\n  } else { throw e; }\n}","preventionTips":["Check authenticationAvailable before issuing authenticated requests","Implement a global 401 interceptor that routes to re-login","Refresh tokens proactively before expiry","Detect concurrent-session invalidation and handle re-auth centrally"],"tags":["http","authentication","network","session"],"backgroundTag":"authentication-required","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}