Breaking change in validateStatus parameter
See original GitHub issueProblem:
This is what README.md says about validateStatus
parameter:
validateStatus
defines whether to resolve or reject the promise for a given HTTP response status code. IfvalidateStatus
returnstrue
(or is set tonull
orundefined
), the promise will be resolved; otherwise, the promise will be rejected.
This parameter supports (as specified) undefined
in 0.18.x but it does not work properly in 0.19.0 despite the documentation does not warn about this change.
Affects version: 0.19.0 (latest)
Steps to reproduce it:
Set validateStatus
property to undefined
value and request anything that returns 404 Not Found
.
Current behavior: It uses the standard validation function (that only accepts 2XX status codes); rejecting any non successful response.
Expected behavior:
It should accept any status code received from server as null
value does.
Reproducible scenario:
const axios = require('axios'); // v0.19.0
axios
.get('https://example.com/404', { validateStatus: undefined })
.catch(console.error);
// output: axios error due to 404 not found
Solution:
Analyze where the bug has been added and fix it.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top GitHub Comments
Indeed, the
README.md
still saysundefined
is a valid value for that parameter.I do not agree #2545 fixes this problem. The behavior for
validateStatus
was modified from0.18.x
to0.19.x
without any warning (release notes), so this should be the procedure:0.19.x
) to maintain backward compatibility.0.20.x
) informing the user about this breaking change.