Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage of onError({ request }) results in TypeError: Response body object should not be disturbed or locked #23

Closed
eliellis opened this issue Jan 26, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@eliellis
Copy link

What version of Elysia is running?

1.2.10

What platform is your computer?

Darwin 24.1.0 arm64 arm

What steps can reproduce the bug?

Run the following:

import { Elysia, t } from "elysia";
import { node } from "@elysiajs/node";

const app = new Elysia({
  adapter: typeof Bun === "undefined" ? node() : undefined,
})
  .onError(({ request }) => {
    return;
  })
  .post("/", ({ body }) => "OK", {
    body: t.Object({
      test: t.String(),
    }),
  })
  .listen(3000);

const res = await fetch("http://localhost:3000/", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ bad: "" }),
});

console.log("status", res.status);

await app.stop(true);

What is the expected behavior?

The above should print status 422. Running the same sample with bun run does print status 422.

What do you see instead?

node:internal/deps/undici/undici:5574
          throw new TypeError(
                ^

TypeError: Response body object should not be disturbed or locked
    at extractBody (node:internal/deps/undici/undici:5574:17)
    at new Request (node:internal/deps/undici/undici:9801:48)
    at nodeRequestToWebstand (file:///Users/eli/code/elysia-node-redirect-issue/node_modules/@elysiajs/node/dist/index.mjs:931:10)
    at Object.get [as request] (eval at composeHandler (file:///Users/eli/code/elysia-node-redirect-issue/node_modules/elysia/dist/compose.mjs:1148:12), <anonymous>:5:81)
    at Array.<anonymous> (/Users/eli/code/elysia-node-redirect-issue/tests/post-with-body-onError-hook.ts:7:15)
    at handle (eval at composeHandler (file:///Users/eli/code/elysia-node-redirect-issue/node_modules/elysia/dist/compose.mjs:1148:12), <anonymous>:59:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)

Node.js v23.6.1

Additional information

No response

Have you try removing the node_modules and bun.lockb and try again yet?

yes

@eliellis eliellis added the bug Something isn't working label Jan 26, 2025
@SaltyAom
Copy link
Member

SaltyAom commented Feb 1, 2025

Fixed with 160bf0e, published under 1.2.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants