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
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/client/src/classes/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ class Client {
data = this.createRequest(data);

const promise = new Promise((resolve, reject) => {
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.

},
})
.then(response => {
return resolve([
new Response(response.status, response.data, response.headers),
Expand Down
Loading