Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally validate argument of the extension factoryFunc when registering route #2

Open
rooftopsparrow opened this issue Mar 22, 2018 · 0 comments

Comments

@rooftopsparrow
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant