test(AxiosError): document and test error.status behaviour#10725
Merged
jasonsaayman merged 2 commits intoaxios:v1.xfrom Apr 15, 2026
Merged
test(AxiosError): document and test error.status behaviour#10725jasonsaayman merged 2 commits intoaxios:v1.xfrom
jasonsaayman merged 2 commits intoaxios:v1.xfrom
Conversation
error.status is set to response.status when a response is available, and is undefined for network-level errors that have no HTTP response. Add an inline comment in the constructor clarifying this contract, and add four regression tests for issue axios#5330 covering: - 4xx errors (error.status === response.status) - 5xx errors - network errors (error.status is undefined) - toJSON includes the status field Fixes axios#5330
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
Fixes #5330.
error.statusis set toresponse.statuswhen a response is available (4xx/5xx errors), and isundefinedfor network-level errors that produce no HTTP response. This was already correctly implemented inv1.xbut was undocumented and had no direct test coverage.Changes
lib/core/AxiosError.js: add inline comment clarifying whenthis.statusis set vs undefinedtests/unit/core/AxiosError.test.js: 4 regression tests covering 4xx, 5xx, network errors (status undefined), and toJSON outputNote
No behaviour change — this is a documentation and test coverage improvement only.
Summary by cubic
Documents and adds regression tests for
AxiosError.status. It matchesresponse.statuswhen a response exists and is undefined for network errors; no runtime change.Description
toJSON()includingstatus.v1.xand addresses issue AxiosError type declaration includes a status field, but implementation does not #5330 by documenting existing behavior.Testing
tests/unit/core/AxiosError.test.jsassert:error.status === response.status.error.statusis undefined anderror.responseis absent.toJSON()includesstatus.Written for commit 3124138. Summary will update on new commits.