Skip to content

Commit 4d256a6

Browse files
AlpAlp
authored andcommitted
fix(bun): wrap response body drain in try/catch for sync errors
The `void response.text().catch(() => {})` pattern only handles async promise rejections. If `response.text` is not a function, a synchronous TypeError is thrown before `.catch()` is reached, rejecting the entire promise chain and preventing the transport from returning status/headers. Wrap in try/catch to handle both: - try/catch: synchronous TypeError (response.text not a function) - .catch(): async rejection (body read fails mid-stream)
1 parent 319f434 commit 4d256a6

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

packages/bun/src/transports/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ export function makeFetchTransport(options: BaseTransportOptions): Transport {
1717
return fetch(options.url, requestOptions).then(response => {
1818
// Drain response body to prevent Bun from retaining the backing ArrayBuffer.
1919
// See: https://github.com/oven-sh/bun/issues/10763, https://github.com/oven-sh/bun/issues/27358
20-
void response.text().catch(() => {});
20+
// try/catch: guards against synchronous TypeError if response.text is not a function.
21+
// .catch(): handles async rejection if body read fails mid-stream (prevents unhandled promise rejection).
22+
try { void response.text().catch(() => {}); } catch {} // eslint-disable-line no-empty
2123

2224
return {
2325
statusCode: response.status,

0 commit comments

Comments
 (0)