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

3.0.0 beta.10: TypeError: Cannot read property 'body' of null #1220

Closed
weijarz opened this issue Jul 24, 2021 · 6 comments · Fixed by #1222
Closed

3.0.0 beta.10: TypeError: Cannot read property 'body' of null #1220

weijarz opened this issue Jul 24, 2021 · 6 comments · Fixed by #1222
Labels

Comments

@weijarz
Copy link

weijarz commented Jul 24, 2021

import fetch from 'node-fetch'

const response = await fetch('https://blog.logrocket.com/feed')
const body = await response.text()

console.log(body)

throws

file:///root/fetchbug/node_modules/node-fetch/src/index.js:99
			response.body.destroy(error);
			         ^

TypeError: Cannot read property 'body' of null
    at file:///root/fetchbug/node_modules/node-fetch/src/index.js:99:13
    at TLSSocket.<anonymous> (file:///root/fetchbug/node_modules/node-fetch/src/index.js:310:6)
    at TLSSocket.emit (events.js:327:22)
    at net.js:673:12
    at TCP.done (_tls_wrap.js:563:7)
software version
node-fetch 3.0.0-beta.10
node v14.16.0
npm 7.17.0
Operating System archlinux
@weijarz weijarz added the bug label Jul 24, 2021
@jimmywarting
Copy link
Collaborator

jimmywarting commented Jul 24, 2021

Able to reproduce (must have something to do with redirects)
works in v2... works in 3.0.0-beta.9 also

@jimmywarting
Copy link
Collaborator

@octet-stream would you like to take a stab at #1220 #1219 before we ship v3?
I'm on vacation ATM. #1064 broke some stuff between beta.9 and beta.10

@octet-stream
Copy link
Contributor

Will see what I can do.

@octet-stream
Copy link
Contributor

octet-stream commented Jul 26, 2021

It seems like the response is null when fixResponseChunkedTransferBadEnding calls its callback after the request has been redirected. There's no check for response being null here:

node-fetch/src/index.js

Lines 98 to 100 in b50fbc1

fixResponseChunkedTransferBadEnding(request_, error => {
response.body.destroy(error);
});

Adding this check fixes this issue. But I'm not sure yet if this is the right solution. And I'm not one of node-fetch members so don't expect match from me because I'm unfamiliar with the codebase :D However I will figure this out.

@tekwiz
Copy link
Member

tekwiz commented Jul 26, 2021

@jimmywarting I'll take a look at this today.

@tekwiz
Copy link
Member

tekwiz commented Jul 26, 2021

@jimmywarting See #1222 for fix

@tekwiz tekwiz linked a pull request Jul 26, 2021 that will close this issue
4 tasks
jimmywarting pushed a commit that referenced this issue Aug 12, 2021
…pty (#1222)

* Fix redirect failing when response is chunked but empty. #1220 #1064

* Handle chunked responses where the final chunk and EOM code are in separate packets and where there is an additional data chunk in the same packet before the final chunk and EOM code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants