Thanks to visit codestin.com
Credit goes to github.com

Skip to content

prevent undefined error codes in settle for non-4xx/5xx st...#7276

Open
VeerShah41 wants to merge 1 commit intoaxios:v1.xfrom
VeerShah41:v1.x
Open

prevent undefined error codes in settle for non-4xx/5xx st...#7276
VeerShah41 wants to merge 1 commit intoaxios:v1.xfrom
VeerShah41:v1.x

Conversation

@VeerShah41
Copy link

…atus codes

Replace array indexing logic with conditional check to ensure proper error code assignment for all HTTP status code ranges.

Previously, the error code selection used:
[ERR_BAD_REQUEST, ERR_BAD_RESPONSE][Math.floor(status / 100) - 4]

This produced undefined for status codes outside 4xx/5xx ranges (1xx, 2xx, 3xx, 6xx+), which could break error handling when users customize validateStatus to reject non-standard status codes.

Now uses:
status >= 400 && status < 500 ? ERR_BAD_REQUEST : ERR_BAD_RESPONSE

This ensures:

  • 4xx codes → ERR_BAD_REQUEST
  • All other error codes → ERR_BAD_RESPONSE

Instructions

Please read and follow the instructions before creating and submitting a pull request:

  • Create an issue explaining the feature. It could save you some effort in case we don't consider it should be included in axios.
  • If you're fixing a bug, try to commit the failing test/s and the code fixing it in different commits.
  • Ensure you're following our contributing guide.

⚠️👆 Delete the instructions before submitting the pull request 👆⚠️

Describe your pull request here.

…atus codes

Replace array indexing logic with conditional check to ensure proper error
code assignment for all HTTP status code ranges.

Previously, the error code selection used:
[ERR_BAD_REQUEST, ERR_BAD_RESPONSE][Math.floor(status / 100) - 4]

This produced undefined for status codes outside 4xx/5xx ranges (1xx, 2xx,
3xx, 6xx+), which could break error handling when users customize
validateStatus to reject non-standard status codes.

Now uses:
status >= 400 && status < 500 ? ERR_BAD_REQUEST : ERR_BAD_RESPONSE

This ensures:
- 4xx codes → ERR_BAD_REQUEST
- All other error codes → ERR_BAD_RESPONSE
@VeerShah41
Copy link
Author

@tomaash

@VeerShah41
Copy link
Author

@adimit

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.

1 participant