From da5e9e21e6241c033278ab1497ce27bcf194f669 Mon Sep 17 00:00:00 2001 From: Hashim Khan <64767361+Hashim1999164@users.noreply.github.com> Date: Thu, 13 Aug 2026 04:46:43 +0500 Subject: [PATCH] Propagate fetch body read errors through pipe streams Wrap responseToReadable reader.read() in try/catch and destroy the Readable with the error so fetch().pipe no longer leaves unhandled promise rejections when the response stream fails. Fixes #1443. --- src/goods.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/goods.ts b/src/goods.ts index 72fb8e8a27..90155097ec 100644 --- a/src/goods.ts +++ b/src/goods.ts @@ -111,8 +111,12 @@ const responseToReadable = (response: Response, rs: Readable) => { return rs } rs._read = async () => { - const result = await reader.read() - rs.push(result.done ? null : Buffer.from(result.value)) + try { + const result = await reader.read() + rs.push(result.done ? null : Buffer.from(result.value)) + } catch (err) { + rs.destroy(err instanceof Error ? err : new Error(String(err))) + } } return rs }