Skip to content

onAfterResponse is not called when responding with an error manually. #1360

@kimzuni

Description

@kimzuni

What version of Elysia is running?

1.3.20

What platform is your computer?

Linux 6.14.0-28-generic x86_64 x86_64

What environment are you using

bun: 1.2.20

Are you using dynamic mode?

Not set. When it is set to false, the issue does not occur.

What steps can reproduce the bug?

import { Elysia } from "elysia";

export const app = new Elysia()
	.onError(() => {
		console.log("handle");
		return "return data";
	})
	.onAfterResponse(() => {
		console.log("logging");
	})
	.get("/test", () => {
		throw new Error("err");
	})
	.listen(3000);

What is the expected behavior?

onAfterResponse should be called even when an error is thrown manually.

curl http://localhost:3000/404 # Both `handle` and `logging` are shown
curl http://localhost:3000/test # Both `handle` and `logging` are shown

What do you see instead?

When requesting an unregistered path, both onError and onAfterResponse are called, but when an error is thrown manually, onAfterResponse is not called.

curl http://localhost:3000/404 # Both `handle` and `logging` are shown
curl http://localhost:3000/test # Only `handle` is shown

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