Skip to content

Throwing from AsyncGenerator does not send headers #1677

@aboqasem

Description

@aboqasem

What version of Elysia is running?

1.4.21

What platform is your computer?

No response

What environment are you using

No response

Are you using dynamic mode?

No response

What steps can reproduce the bug?

It is breaking cors plugin.

Something like this:

import { Elysia, sse, status } from 'elysia'

const app = new Elysia()
    .get('/fail', async function* ({ set }) {
        set.headers["access-control-allow-origin"] = "*";
        throw status(500);
    })
    .get('/work', async function* ({ set }) {
        set.headers["access-control-allow-origin"] = "*";
        return status(500); // <- returns
    })
    .listen(3000)
import { app } from '../server'
import { treaty } from '@elysiajs/eden'

const api = treaty(app);

(async () => {
    const fail = await api.fail.get();
    console.log("fail.headers", fail.headers);

    const work = await api.work.get();
    console.log("work.headers", work.headers);
})();

What is the expected behavior?

headers to be sent, cors plugin to work.

What do you see instead?

headers not sent.

Additional information

No response

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

No response

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