-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
I was thinking we should allow the definition of an extension to also expose how the arguments to the factoryFunc are validated ( similar to validating that the route definition itself is valid ).
For example:
// extension
const extension = {
name: 'isGood',
factoryFunc: (options = {}) => (req, res, next) => {
if (options.dog != 'good') return next(new Error('bad pupper!'))
else next()
}
// route definition
const route = {
method: 'get',
path: '/puppers',
isGood: { doge: 'good' },
handle: (req, res) => { res.send('ok!') }As you can see, someone accidentally used doge instead of dog in the configuration of the isGood extension without realizing. Now the route will "accidentally" send errors to the client instead of noticing the error register of the route while validating the config options passed to the factory func.
My proposal is have some mechanics for validating what is passed to the factoryFunc when we register the route. Basically, put a validate() on the extension too.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels