How to use Validator ? Context is not finalized
As soon as I try to use validator, Hono complains.
api-hono:dev: error: Context is not finalized. Did you forget to return a Response object or
await next()
?
Any idea? :\
EDIT:
I'm using Superforms to send the request. Devtool says the data it is indeed Form Data.
If I replace form with json, it doesnt throw the error, but the value is empty9 Replies
Just do await next();
If you want to save the updated body you will have to do to C.req.setValdate something
On phone so canβt really type
Shit, really ? I didn't see that in any example I think... π
Interesting can share the docs page where you say it
If there is an issue I will update them
Thank you very much for taking the time, you're amazing! I'll do that and report back β€οΈ
https://hono.dev/docs/guides/validation#manual-validator
Interesting, I will take a look at this and will update it
don't do anxiety to reply lol, just leaving this here for when you're home and have time π
Post form test in the repo: https://github.com/honojs/hono/blob/73ff6c0e82d66468e28ed439481220f56ab03882/src/validator/validator.test.ts#L217
But it doesnt work on my end.
On my end, I tried adding next, but it doesnt like it.
package.json:
"hono": "^4.5.11"
GitHub
hono/src/validator/validator.test.ts at 73ff6c0e82d66468e28ed439481...
Web framework built on Web Standards. Contribute to honojs/hono development by creating an account on GitHub.
Thanks I will take a look π
I might have found the underlying issue...
I'm using
const body = await c.req.parseBody()
so I need an async function in the main handler. and then I try to return values:
https://hono.dev/docs/api/request#parsebody
This throws an error api-hono:dev: error: Context is not finalized. Did you forget to return a Response object or
await next()?
Found the culprit !!!
The first middleware that is suppose to make my db connection inside context causes this.
Strange as I was succesful into inserting requests but I must have changed something somewhere. π
adding await
before next()
solves the issue π€¦Great!
π