2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +03:00
Files
axios/lib/core
Veer Shah 5107ee69ae fix: prevent undefined error codes in settle (#7276)
* fix(core): prevent undefined error codes in settle for non-4xx/5xx status 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

* test(core): add unit tests for settle error code assignment

Cover the boundary conditions that were previously untested:
- 4xx status codes → ERR_BAD_REQUEST
- 5xx status codes → ERR_BAD_RESPONSE
- Non-4xx/5xx codes rejected via custom validateStatus → ERR_BAD_RESPONSE (defined, not undefined)

These tests would have caught the original array-indexing bug where
Math.floor(status/100) - 4 returned negative/out-of-range indices
for 1xx, 2xx, 3xx, and 6xx+ status codes, resulting in undefined error.code.

* test(core): describe behavior, not PR history, in settle tests

---------

Co-authored-by: VeerShah41 <https://github.com/VeerShah41>
Co-authored-by: Jason Saayman <jasonsaayman@gmail.com>
2026-05-01 19:24:28 +02:00
..

axios // core

The modules found in core/ should be modules that are specific to the domain logic of axios. These modules would most likely not make sense to be consumed outside of the axios module, as their logic is too specific. Some examples of core modules are:

  • Dispatching requests
    • Requests sent via adapters/ (see lib/adapters/README.md)
  • Managing interceptors
  • Handling config