Package Exports
- hapi-default-payload
- hapi-default-payload/lib/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (hapi-default-payload) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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')
]);