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

option to manually flush/write body to browser when done #541

Open
platinumindustries opened this issue Jul 23, 2022 · 2 comments
Open

option to manually flush/write body to browser when done #541

platinumindustries opened this issue Jul 23, 2022 · 2 comments
Labels
need info Further information requested

Comments

@platinumindustries
Copy link

I have so far been unable to sort out this issue. I have a code that uses the MongoDb driver and whenever a do a fetch operation, i can no longer write to .response.body, e.g:

Once I call - await users.findOne({ email: req.email }) , I get an error when I do ctx.response.body.

As a workaround, is there a way i can force write the response, or a flag i can use to force oak not to close the response until i explicitly tell it to?

The error I get: The response is not writable.

@cmorten
Copy link
Contributor

cmorten commented Aug 30, 2022

#148 seems to be reasonably well described - care is needed when using async await to make sure subsequent middleware aren’t executed before your promise resolves (including Oak’s default response if none is supplied).

Do you have a more complete code example?

@kitsonk
Copy link
Collaborator

kitsonk commented Apr 25, 2023

As @cmorten says, a more complete code example would be needed to help, but this usually occurs when middleware is not holding onto the request in a way that indicates it is still processing, specifically not invoking or returning the next(). When the middleware "chain" is dropped, oak assumes the body is set synchronously and sends the response.

@kitsonk kitsonk added the need info Further information requested label Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need info Further information requested
Projects
None yet
Development

No branches or pull requests

3 participants