H
Hono6mo ago
bombillazo

Return early from middleware

Hello, I want to return a 200 response from a middleware if certain conditions are not met, else run await and cleanup after the await. How can I return early from the middleare function?
2 Replies
bombillazo
bombillazoOP6mo ago
So the error I had was unrelated to the return, returning normally early with the response object works!
Aditya Mathur
Aditya Mathur6mo ago
You also just do return c.text("Works!") inside the middleware, this should be before await next() line. Also if you want to throw an error try using HTTPException

Did you find this page helpful?