Skip to content

Instantly share code, notes, and snippets.

@jasisk
Created June 18, 2026 21:30
Show Gist options
  • Select an option

  • Save jasisk/03dcc644dbe2a432ae69cee612778ac1 to your computer and use it in GitHub Desktop.

Select an option

Save jasisk/03dcc644dbe2a432ae69cee612778ac1 to your computer and use it in GitHub Desktop.
diff --git a/node_modules/node-fetch/lib/index.es.js b/node_modules/node-fetch/lib/index.es.js
index aae9799..ef123d6 100644
--- a/node_modules/node-fetch/lib/index.es.js
+++ b/node_modules/node-fetch/lib/index.es.js
@@ -1740,7 +1740,7 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {
// if a data listener is still present we didn't end cleanly
const hasDataListener = socket && socket.listenerCount('data') > 0;
- if (hasDataListener && !hadError) {
+ if (hasDataListener && !hadError && !response.complete) {
const err = new Error('Premature close');
err.code = 'ERR_STREAM_PREMATURE_CLOSE';
errorCallback(err);
diff --git a/node_modules/node-fetch/lib/index.js b/node_modules/node-fetch/lib/index.js
index 567ff5d..580872b 100644
--- a/node_modules/node-fetch/lib/index.js
+++ b/node_modules/node-fetch/lib/index.js
@@ -1744,7 +1744,7 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {
// if a data listener is still present we didn't end cleanly
const hasDataListener = socket && socket.listenerCount('data') > 0;
- if (hasDataListener && !hadError) {
+ if (hasDataListener && !hadError && !response.complete) {
const err = new Error('Premature close');
err.code = 'ERR_STREAM_PREMATURE_CLOSE';
errorCallback(err);
diff --git a/node_modules/node-fetch/lib/index.mjs b/node_modules/node-fetch/lib/index.mjs
index 2863dd9..8a491b9 100644
--- a/node_modules/node-fetch/lib/index.mjs
+++ b/node_modules/node-fetch/lib/index.mjs
@@ -1738,7 +1738,7 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {
// if a data listener is still present we didn't end cleanly
const hasDataListener = socket && socket.listenerCount('data') > 0;
- if (hasDataListener && !hadError) {
+ if (hasDataListener && !hadError && !response.complete) {
const err = new Error('Premature close');
err.code = 'ERR_STREAM_PREMATURE_CLOSE';
errorCallback(err);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment