Hapi plugin to default the request payload to an empty object
npm install hapi-default-payloadA 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...
``js`
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
`js
const hapi = require('@hapi/hapi');
const server = new hapi.Server({});
server.register([
require('hapi-default-payload')
]);
``