mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
Should fix https://github.com/oven-sh/bun/issues/24104 ### What does this PR do? This PR is changing `ERR_BODY_ALREADY_USED` to be TypeError instead of Error. ### How did you verify your code works? A test case added to verify that request call correctly throws a TypeError after another request call on the same Request, confirming the fix addresses the issue. --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
25 lines
778 B
TypeScript
25 lines
778 B
TypeScript
import { describe, expect, it } from "bun:test";
|
|
|
|
describe("body-mixin-errors", () => {
|
|
it.concurrent.each([
|
|
["Response", () => new Response("a"), (b: Response | Request) => b.text()],
|
|
[
|
|
"Request",
|
|
() => new Request("https://example.com", { body: "{}", method: "POST" }),
|
|
(b: Response | Request) => b.json(),
|
|
],
|
|
])("should throw TypeError when body already used on %s", async (type, createBody, secondCall) => {
|
|
const body = createBody();
|
|
await body.text();
|
|
|
|
try {
|
|
await secondCall(body);
|
|
expect.unreachable("body is already used");
|
|
} catch (err: any) {
|
|
expect(err.name).toBe("TypeError");
|
|
expect(err.message).toBe("Body already used");
|
|
expect(err instanceof TypeError).toBe(true);
|
|
}
|
|
});
|
|
});
|