Content-Length: 272448 | pFad | http://github.com/node-fetch/node-fetch/commit/8bc3a7c85f67fb81bb3d71c8254e68f3b88e9169

48 fix: socket variable testing for undefined (#1726) · node-fetch/node-fetch@8bc3a7c · GitHub
Skip to content

Commit 8bc3a7c

Browse files
joamagLinusUjimmywarting
authored
fix: socket variable testing for undefined (#1726)
* fix: socket variable testing for undefined Avoid issue where socket event was not triggered and local socket vraible is not defined. This issue is reproducible only using deno. * chore: made socket test capture simpler Only controls the execution of the section that uses socket. * Update src/index.js Co-authored-by: Linus Unnebäck <linus@folkdatorn.se> * Update index.js --------- Co-authored-by: Linus Unnebäck <linus@folkdatorn.se> Co-authored-by: Jimmy Wärting <jimmy@warting.se>
1 parent afb36f6 commit 8bc3a7c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,11 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {
362362
const {headers} = response;
363363
if (headers['transfer-encoding'] === 'chunked' && !headers['content-length']) {
364364
response.once('close', hadError => {
365-
// if a data listener is still present we didn't end cleanly
366-
const hasDataListener = socket.listenerCount('data') > 0;
365+
// tests for socket presence, as in some situations the
366+
// the 'socket' event is not triggered for the request
367+
// (happens in deno), avoids `TypeError`
368+
// if a data listener is still present we didn't end cleanly
369+
const hasDataListener = socket && socket.listenerCount('data') > 0;
367370

368371
if (hasDataListener && !hadError) {
369372
const err = new Error('Premature close');

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/node-fetch/node-fetch/commit/8bc3a7c85f67fb81bb3d71c8254e68f3b88e9169

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy