mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
5107ee69ae
* 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>