gitbutlerapp/gitbutler · error · ApiError
Login token expired. Please log in to GitButler again.
Error message
Login token expired. Please log in to GitButler again.
What it means
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.
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
Example fix
// before
const data = await httpClient.get(`projects/${projectId}`);
// after
try {
const data = await httpClient.get(`projects/${projectId}`);
} catch (e) {
if (e instanceof ApiError && e.response?.status === 401) {
uiStore.setNeedsAuth(true); // prompt re-login
return;
}
throw e;
} Defensive patterns
Strategy: try-catch
Validate before calling
const token = get(tokenStore);
if (!token) {
await promptRelogin(); // avoid firing requests without a token
return;
} Type guard
function isAuthError(e: unknown): e is ApiError {
return e instanceof ApiError && e.response?.status === 401;
} Try / catch
try {
await httpClient.get(path);
} catch (e) {
if (e instanceof ApiError && e.message.includes('Login token expired')) {
await loginService.loginWithEmail(email, password); // re-auth then retry
} else { throw e; }
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Authentication and authorization failures — expired tokens, bad credentials, and missing scopes.
Related errors
- Anthropic API error ( )
- Bitbucket request failed
- Bitbucket request failed
- Download failed with HTTP status
- Download of failed with HTTP status
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/cd3131b52e45aa27.
Report an issue: GitHub.
Appendix: source
Thrown at packages/shared/src/lib/network/httpClient.ts:114
async patch<T>(path: string, opts?: RequestOptions) {
return await this.requestJson<T>(path, { ...opts, method: "PATCH" });
}
async delete<T>(path: string, opts?: RequestOptions) {
return await this.requestJson<T>(path, { ...opts, method: "DELETE" });
}
async postRaw(path: string, opts?: RequestOptions) {
return await this.request(path, { ...opts, method: "POST" });
}
}
async function parseResponseJSON(response: Response) {
if (response.status === 204 || response.status === 205) {
return null;
} else if (response.status === 401) {
throw new ApiError("Login token expired. Please log in to GitButler again.", response);
} else if (response.status >= 400) {
const text = await response.text();
if (text.includes("401 Unauthorized") || text.includes("401 unauthorized")) {
throw new ApiError("Login token expired. Please log in to GitButler again.", response);
}
throw new ApiError(`HTTP Error ${response.statusText}: ${text}`, response);
} else {
return await response.json();
}
}
function formatBody(body?: FormData | object) {
if (!body) return;
return body instanceof FormData ? body : JSON.stringify(body);
}
View on GitHub (pinned to 58e5313667)