Repository navigation
Conversation
`execute()` used `AxiosError.from(e)` before checking `error.response`. `AxiosError.from(error, code, config, request, response)` builds a fresh `AxiosError` and assigns `response` only from its own fifth argument, which was not passed - so `error.response` was always `undefined` and the branch never returned a response. The fallback is currently masked by `validateStatus: () => true`, which keeps axios from rejecting on an HTTP status at all, so the branch was dead code. It would not have preserved the intended behavior had a caller overridden `validateStatus` in its own axios config. Read the response off the original error via axios' `isAxiosError()` type guard instead, and reword the comment to describe the actual arrangement. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
mfal
marked this pull request as ready for review
September 24, 2026 15:55
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.
Problem
Request.execute()caught a rejection and did:The comment above it claimed this preserves the previous behavior of returning the response even for HTTP errors. It could not:
AxiosError.from(error, code, config, request, response)builds a freshAxiosErrorand assignsresponseonly from its own fifth argument, which was not passed here. Soerror.responsewas alwaysundefinedand the method always rethrew.Confirmed against the installed axios 1.15.2 (
node_modules/axios/lib/core/AxiosError.js):Today this is masked because
buildAxiosConfig()setsvalidateStatus: () => true, so axios never rejects on an HTTP status in the first place — the branch was dead code that would not have protected the intended behavior if that option were ever changed or overridden by a caller's axios config.Change
Read the response off the original error using axios' named
isAxiosError()type guard, keeping the fallback as live code:The type guard also narrows
e, so no cast on the error is needed. The comment is reworded to describe the actual arrangement:validateStatus: () => trueis the primary mechanism, and this branch is the fallback for callers that override it.Passing
e.responseback intoAxiosError.fromwould just rebuild an error object we immediately discard; dropping the branch entirely would make the "return all responses" contract depend solely on no caller ever overridingvalidateStatus.Tests
Request.test.tsgains anerror handlingblock covering three cases: the response is returned, an axios error without a response is rethrown, and a non-axios error is rethrown.requestFnhad to be typed — an untypedjest.fn()from@jest/globalsinfersneverargs and rejectsmockRejectedValue.Verified the new test is not vacuous: with the old
AxiosError.fromcode restored,returns an axios error's response instead of throwingfails (1 failed, 19 passed); with the fix all 20 pass.🤖 Generated with Claude Code