Fix retry predicate's dead instanceof Error check for 404s - #68
Merged
abayomicornelius merged 4 commits intoAug 18, 2026
Merged
Conversation
Contributor
|
clean work |
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.
Summary
The global React Query retry predicate checked
error instanceof Errorto skip retrying 404s, but the axios response interceptor always rejected with a plain{ code, message, details }object literal, never a realError. The check could never match, so the// Don't retry 404sbranch was dead in practice — every backend-routed query failure retried up to twice, including genuine 404s the code explicitly intended to fail fast on.Implemented the issue's second suggested fix (making the interceptor reject with a real
Errorsubclass), combined with the first's refinement (checking a stable code instead of message substring-matching):ApiRequestError extends Error implements ApiError(src/lib/api.ts) carryingcode/detailsas real properties. The interceptor now rejects with an instance of it instead of a plain object — extracted into a standalonenormalizeApiErrorfunction so it's unit-testable without relying on axios's internal interceptor-handler storage.codeprefers the backend's owndata.code; when the backend doesn't send one, a 404 status is normalized to a stable'NOT_FOUND'code (derived from the real HTTP status — a reliable, backend-convention-independent signal) instead of falling through to'UNKNOWN_ERROR'.instanceof Erroreverywhere else in the app that assumed it, not just this one predicate — every hook already types its query error asuseQuery<T, Error>, which was previously a lie about the actual runtime shape.src/lib/queryRetry.tsasshouldRetryQuery, checkingerror instanceof ApiRequestError && (error.code === 'NOT_FOUND' || error.message.includes('not found'))— code-based as the primary signal, message-substring kept as a fallback. Pulled out ofApp.tsxboth for direct testability (per the issue's own suggested testing strategy) and becausereact-refresh/only-export-components(enforced here at--max-warnings 0) requires component files to only export components.Test plan
normalizeApiError/ApiRequestError: produces a realErrorinstance, carries backend-suppliedcode/message/detailsthrough unchanged, derives'NOT_FOUND'from a 404 status when the backend sends none, prefers a backend-supplied code when present, falls back to'UNKNOWN_ERROR'/a generic message otherwiseshouldRetryQuery: doesn't retry anApiRequestErrorwithcode: 'NOT_FOUND', doesn't retry one whose message mentions "not found" under a different code, retries otherApiRequestErrors and non-ApiRequestErrorvalues up to the failure-count limit (proving a plain object that happens to look 404-shaped is correctly not special-cased)npm test— 106/106 passingnpx tsc --noEmit— cleannpm run lint— clean (--max-warnings 0)npm run build— succeedsCloses #60