Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

lopenchi
Copy link

@lopenchi lopenchi commented Feb 18, 2025

Fixes

Related PR: #1327

fix: Support 204 response in axios

Checklist

  • I acknowledge that all my contributions will be made under the project's license
  • I have made a material change to the repo (functionality, testing, spelling, grammar)
  • I have read the Contribution Guidelines and my PR follows them
  • I have titled the PR appropriately
  • I have updated my branch with the main branch
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation about the functionality in the appropriate .md file
  • I have added inline documentation to the code I modified

If you have questions, please file a support ticket.

@lopenchi lopenchi changed the title Support 204 response in axios fix: Support 204 response in axios Feb 18, 2025
axios(data)
axios(data, {
validateStatus: function (status) {
return status >= 200 && status < 300 || status === 204;
Copy link

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 👀

Copy link
Author

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

Copy link

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?

Copy link
Author

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

Copy link
Author

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

Copy link

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.

Copy link
Author

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

Copy link

@bnb bnb Feb 18, 2025

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.

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.

3 participants