From 35e17f6a99691e8f7e75d8d760bb7e4806e52595 Mon Sep 17 00:00:00 2001 From: Venkata Krishnan S <114849299+venkat22022202@users.noreply.github.com> Date: Wed, 1 Apr 2026 18:17:02 +0530 Subject: [PATCH] fix: handle stream read errors in responseToReadable to prevent unhandled rejections Fixes #1443 Co-Authored-By: Claude Opus 4.6 (1M context) --- 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 }