Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
request()andrequestMultipart()infrontend/src/api/client.tseach 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 thanwindow.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 singledropExpiredSession()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 warningscd frontend && npx vitest run src/apiβ 7 files / 40 tests pass (these exerciserequest()/requestMultipart()indirectly through the variousapi/*modules)cd frontend && npm run buildβ builds cleanlyChecklist
cd frontend && npm run check && npm run lint && npm test && npm run buildpasses (backend untouched, somake lint && make testdoesn't apply)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 thedropExpiredSessionblock 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