Skip to content

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

@rooftopsparrow

Description

@rooftopsparrow

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions