You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use a bare bones middleware, and log in the middleware
import{Hono}from'hono';constapp=newHono()app.use(async(ctx,next)=>{// typed as void, but actual value is a Context object.constnextResult=awaitnext();console.log('nextResult',nextResult);});
What is the expected behavior?
I expect the result of await next() to be undefined, since the return type is void.
What do you see instead?
I see the actual value as a full Hono Context object.
Additional information
Also tested on Hono 4.0.1.
💭 The returned Context object enables a lot of additional use cases. ie. checking ctx.error for if a wrapped middleware threw. Otherwise, middlewares are unable to detect if any wrapped middleware has thrown, since await next() does not appear to ever throw.
The text was updated successfully, but these errors were encountered:
Exactly, the return value from await next() is Context, so it's better to type it. But, only by changing, another type error will occur if return next() in a middleware:
But, if so, a user may return unexpected values in the middleware:
app.use(async(c,next)=>{return'something'})
We should avoid it because this will cause runtime errors. Ideally, after doing await next(), it should be allowed to return unknown, but this seems difficult.
And we can handle the Context object like this. Is not enough?
What version of Hono are you using?
4.1.4
What runtime/platform is your app running on?
Cloudflare workers
What steps can reproduce the bug?
Use a bare bones middleware, and log in the middleware
What is the expected behavior?
I expect the result of
await next()
to beundefined
, since the return type isvoid
.What do you see instead?
I see the actual value as a full Hono
Context
object.Additional information
4.0.1
.ctx.error
for if a wrapped middlewarethrew
. Otherwise, middlewares are unable to detect if any wrapped middleware hasthrow
n, sinceawait next()
does not appear to everthrow
.The text was updated successfully, but these errors were encountered: