Skip to content

Incorrect HTTP status during onRequest/onAfterResponse #1445

@ConnectivityChris

Description

@ConnectivityChris

What version of Elysia is running?

1.4.7

What platform is your computer?

Darwin 24.6.0 arm64 arm

What environment are you using

Bun 1.1.20

Are you using dynamic mode?

No

What steps can reproduce the bug?

I'm using Better Auth and have noticed that during the lifecycle hooks I am getting the incorrect HTTP status in the set object

The response and responseValue that comes back from the Better Auth handler is correct, but it's being mapped to a 200 no matter the response status

{
  request: Request (69 bytes) {
    method: "POST",
    url: "http://localhost:3001/auth/api/sign-in/email",
    headers: Headers {...
    ReadableStream {...}
  },
  store: {
    startTime: 414435.075333,
    endTime: 414594.388708,
    responseTime: 159.313375000027,
  },
  qi: -1,
  path: "/auth/api/sign-in/email",
  url: "http://localhost:3001/auth/api/sign-in/email",
  redirect: [Function: redirect],
  status: [Function: status],
  set: {
    headers: {...,
    status: 200, <<<<<<<<<<< THIS SHOULD BE 401
    cookie: {},
  },
  server: [Getter],
  params: {
    "*": "api/sign-in/email",
  },
  headers: {...},
  cookie: {...},
  query: [Object: null prototype] {},
  route: "/auth/*",
  log: undefined,
  responseValue: Response (0 KB) {
    ok: false,
    url: "",
    status: 401, <<<<<<<<<< THIS IS 401
    statusText: "UNAUTHORIZED",
    headers: Headers {},
    redirected: false,
    bodyUsed: true
  },
  response: Response (0 KB) {
    ok: false,
    url: "",
    status: 401, <<<<<<<<<< THIS IS 401
    statusText: "UNAUTHORIZED",
    headers: Headers {},
    redirected: false,
    bodyUsed: true
  },
}
const app = new Elysia()
  .onAfterResponse({ as: "global" }, (ctx) => {
    console.log(ctx);
  });

The handler returns the correct status to the browser though

Image

What is the expected behavior?

The set.status should match the response and responseValue status

What do you see instead?

set.status returns 200 no matter the responseValue/response

Additional information

No response

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

yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions