3.0.0 • Published 4 years ago

hapi-default-payload v3.0.0

Weekly downloads
10
License
MIT
Repository
github
Last release
4 years ago

hapi-default-payload

A tiny plugin to default the request.payload to an empty object (similar to the pre Hapi 9+ behavior). This can be useful if you want more descriptive Joi error messages in response to requests that are missing payload data from the request body.

For example, the error message for the schema...

  Joi.object.keys({
    a: Joi.number().required(),
    b: Joi.string().required()
  })

can become more detailed with this plugin...

ValidationError: child "a" fails because ["a" is required]. child "b" fails because ["b" is required]

as opposed to the technically accurate but more abrupt and less helpful...

ValidationError: "value" must be an object

Registering the plugin

const hapi = require('@hapi/hapi');

const server = new hapi.Server({});

server.register([
  require('hapi-default-payload')
]);
3.0.0

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.0.0

9 years ago