Allow custom status codes in Router guard responses
brynne8 opened this issue · comments
Hello,
I've been using the @stricjs/router
package and noticed that the current implementation of the .guard()
method only allows returning null
to trigger a 404 response. In some scenarios, it would be beneficial to return other status codes, such as 400, 403, etc., based on the guard's logic.
Example:
import { Router } from '@stricjs/router';
export default new Router()
// Currently, this only triggers a 404 response
.guard('/', req => verify(req))
.get('/', () => new Response('Hi'))
.use(404);
Suggestion:
It would be great if the .guard()
method could be enhanced to support returning custom status codes or even custom responses. This would provide more flexibility in handling different scenarios.
Thank you for considering this enhancement!
I can do something like this
Customize the 404 return for each path
Or maybe add another property to context
@brynne8
Maybe a fail function should be good
app.reject('/', /* Handler here */)
I will implement that for 4.0.11