bug: manipulating cookies in the error hook gives the error Cannot set headers after they are sent to the client
#2771
Labels
Cannot set headers after they are sent to the client
#2771
Environment
Node.js: 18.20.3
Nitropack: 2.9.7
Reproduction
https://stackblitz.com/edit/github-dyj94s
Describe the bug
I created a plugin and set up an error hook, in the error hook I return a promise and use setTimeout to execute resolve, simulating the situation of awaiting a promise (possibly performing redis operations, etc).
However, it seems that when executing the error hook, the response headers were sent directly without waiting for the hook to finish executing, which resulted in a
Cannot set headers after they are sent to the client
error in the setCookie in the setTimeout.I don't know if this is intentional or if it's a hookable/h3 package error, but since I'm writing a session package, I need to handle session changes as well when the error occurs. Or am I using it incorrectly?
I will provide additional information if needed. Thank you.
Additional context
No response
Logs
The text was updated successfully, but these errors were encountered: