Skip to content

πŸ› οΈ Refactor: dedupe expired-session handling in the API client - #509

Draft
jnnngs wants to merge 1 commit into
mainfrom
claude/bold-curie-714hhr
Draft

jnnngs wants to merge 1 commit into
mainfrom
claude/bold-curie-714hhr

Conversation

@jnnngs

@jnnngs jnnngs commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

What and why

request() and requestMultipart() in frontend/src/api/client.ts each carried an identical 8-line block for handling a session that couldn't be refreshed: clear auth state, show a toast, and lazily navigate to /login (with the comment explaining why that navigation is done via the router rather than window.location). Any future change to that behaviour β€” the toast copy, the redirect target, the reasoning comment β€” had to be made twice and kept in sync by hand. Extracted the block into a single dropExpiredSession() helper that both call sites now use.

No behavior change: the extracted function is a byte-for-byte copy of the duplicated code, called from the same two places at the same point in the control flow.

How you tested it

  • cd frontend && npm run check β€” passes (tsc -b)
  • cd frontend && npm run lint β€” passes, zero warnings
  • cd frontend && npx vitest run src/api β€” 7 files / 40 tests pass (these exercise request()/requestMultipart() indirectly through the various api/* modules)
  • cd frontend && npm run build β€” builds cleanly

Checklist

  • cd frontend && npm run check && npm run lint && npm test && npm run build passes (backend untouched, so make lint && make test doesn't apply)
  • Backend tests ran against a database β€” n/a, no backend changes
  • I read the relevant section of CLAUDE.md and followed its conventions
  • No unrelated refactoring, renames or comment additions in this diff

If it applies

None of the "If it applies" items apply β€” this is a pure client-side extraction of duplicated code with no new surface, migration, notification type, page, env var, capability, or UI change.

Notes for reviewers

Deliberately left the 401-detection condition (res.status === 401 && !isRetry && ...) duplicated rather than also extracting it into a predicate β€” extracting it added enough lines to push the diff needlessly larger for a much smaller piece of duplication, and the dropExpiredSession block was the part actually worth centralizing (it's the part carrying the "why" comment and the side effects).

πŸ€– Generated with Claude Code

https://claude.ai/code/session_01VGNJ41qzCnHvQ2VYDaZw2X


Generated by Claude Code

request() and requestMultipart() repeated the identical clear-auth,
toast, and SPA-navigate-to-login block verbatim, including its
comment. Extract it into dropExpiredSession() so the logic (and the
reasoning for it) exists in one place.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VGNJ41qzCnHvQ2VYDaZw2X
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants