Skip to content

Commit 27969ed

Browse files
authored
Prevent using request body before cloning it (#1364)
* fix bun issue * add comments
1 parent 1f3fefa commit 27969ed

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/openapi-fetch/src/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,13 @@ export default function createClient<Paths extends {}>(clientOptions: ClientOpti
6868

6969
// parse response (falling back to .text() when necessary)
7070
if (response.ok) {
71-
let data: any = response.body;
71+
let data: any; // we have to leave this empty here so that we don't consume the body
7272
if (parseAs !== "stream") {
7373
const cloned = response.clone();
7474
data = typeof cloned[parseAs] === "function" ? await cloned[parseAs]() : await cloned.text();
75+
} else {
76+
// bun consumes the body when calling response.body, therefore we need to clone the response before accessing it
77+
data = response.clone().body;
7578
}
7679
return { data, response: response as any };
7780
}

0 commit comments

Comments
 (0)