Correct way to identify empty response body
See original GitHub issueThis would solve…
Even if there is no response body, undici handles it by returning a stream with 0 length. Currently the only way to tell if you should be trying to parse the body is response.body._readableState.length
, which feels a lot like delving deep into internals.
The implementation should look like…
Additional getter on response would allow to solve this problem without performance overhead:
response.isBodyPresent // getter that checks _readableState.length
I have also considered…
This can also be addressed via documentation, if it is recommended to resolve this in a different way, e. g. by trusting statusCode === 204.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
What is the best way to check for empty request Body?
The EOF check can work if you're only checking for the empty body, but I would still also check for other error cases...
Read more >Tests for empty response body - Help - Postman community
Hi , I have below test: pm.test("Verify the status and name" , function () { var jsonData = pm.response.json(); pm.expect(jsonData[0].name, ...
Read more >Response with empty body - is this a problem? - jQuery Forum
I call an API on the server side to tell the server that I don't have any body in response. The server replies...
Read more >5 Ways to Check If an Object Is Empty in JavaScript | Built In
5 Ways to Check If an Object Is Empty in JavaScript · 1. Use Object.keys · 2. Loop Over Object Properties With for…in...
Read more >Fetch - The Modern JavaScript Tutorial
The browser starts the request right away and returns a promise that ... Response provides multiple promise-based methods to access the body ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
A few notes:
What I did in the past in those cases is to check the content-type header.
Yes it does.