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

Undocumented breaking change #978

Closed
1 task done
lpinca opened this issue Dec 8, 2019 · 8 comments
Closed
1 task done

Undocumented breaking change #978

lpinca opened this issue Dec 8, 2019 · 8 comments

Comments

@lpinca
Copy link
Contributor

lpinca commented Dec 8, 2019

What would you like to discuss?

There seems to be an undocumented breaking change in got@10 when the response body is empty and the responseType option is set to 'json'.

const got = require('got');
const { createServer } = require('http');

const server = createServer(function(request, response) {
  response.end();
});

server.listen(function() {
  const { port } = this.address();

  got(`http://localhost:${port}`, { responseType: 'json' })
    .then(function(response) {
      console.log(response.body);
    })
    .catch(console.error)
    .finally(function() {
      server.close();
    });
});

The promise is rejected with a got.ParseError.

In got@9.6.0 the same code with the json option set to true, returns a promise which is resolved and response.body is set to an empty string.

Is the breaking change intentional?

Checklist

  • I have read the documentation.
@szmarczak
Copy link
Collaborator

An empty string is still valid JSON.

@szmarczak
Copy link
Collaborator

It has been mentioned in release notes:

image

@lpinca
Copy link
Contributor Author

lpinca commented Dec 8, 2019

From the reply I think I was not clear or the report was not read carefully. My expectation is that no error is thrown when the response body is empty. got@10 throws.

@lpinca
Copy link
Contributor Author

lpinca commented Dec 8, 2019

@szmarczak can you please reopen or clarify?

@lpinca
Copy link
Contributor Author

lpinca commented Dec 8, 2019

An empty string is still valid JSON.

In the sense that now you try to JSON.parse() it? Even if you know that it will fail? It wasn't like this in got@9.

If the change is intended I'm fine with it but it should be documented and no, this

Don't throw on 204 No Content when parsing response (#925) 518f0f5

is not enough because the change affects all responses not only 204.

@szmarczak
Copy link
Collaborator

This is fixed in 071bf5e I'll also write a test for it.

@szmarczak
Copy link
Collaborator

This is tested here: d709fd7

@szmarczak
Copy link
Collaborator

Sorry for misunderstanding the issue. Indeed, this was a regression.

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

No branches or pull requests

2 participants