-
Notifications
You must be signed in to change notification settings - Fork 780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Support 204 response in axios #1428
base: main
Are you sure you want to change the base?
Conversation
a0a0a14
to
600b377
Compare
axios(data) | ||
axios(data, { | ||
validateStatus: function (status) { | ||
return status >= 200 && status < 300 || status === 204; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure || status === 204
here is not ever going to be hit because if status
is 204
, the first condition will be met 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep but it is not working, you can see tests were skipped before. And it is how axios worked
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand - if you don't include || status === 204
in this line, the tests fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, axios do not support 204 responses if this line is not added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check this related PR: #1327 where tests that returns 204 were skipped
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I understand. I'm not talking about the whole line, I'm specifically speaking about the contents of the line.
In code, here's what I mean:
const status = 204
console.log(status >= 200 && status < 300 || status === 204) // returns true
const status = 204
console.log(status >= 200 && status < 300) // returns true
both of these return true because if status
is 204
, status satisfies status >= 200 && status < 300
, meaning that || status === 204
is a dead code path that will never be hit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it! So I think this change is not needed.
What about not skipping the tests ? I think it has been already fixed in axios or prism
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the change might still be needed - not sure either way! If it is, this line specifically should be tweaked so we're not shipping a dead code path that will never be executed. The solution to my original comment would be to simply drop || status === 204
from the line.
Fixes
Related PR: #1327
fix: Support 204 response in axios
Checklist
If you have questions, please file a support ticket.