hapi-default-payload

3.0.0 • Public • Published

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')
]);

Readme

Keywords

Package Sidebar

Install

npm i hapi-default-payload

Weekly Downloads

382

Version

3.0.0

License

MIT

Unpacked Size

6.83 kB

Total Files

10

Last publish

Collaborators

  • erik.forsman-lob
  • jkleung11
  • tanya.sah
  • hunteryoakum
  • rdimouro7373
  • lobstertroy
  • joshnkoy
  • michel_lob
  • haroutrs
  • kjones_lob
  • eamon-barisone
  • nathanielwaldschmidtlob
  • zach.reed
  • richpodrazalob
  • kencrim
  • jorgelob
  • nick-place-lob
  • andrew.guterres
  • ajorczak
  • hanqingchen-lob
  • juan.frissdekereki
  • mmorgan-lob
  • karankwatra-lob
  • joey-bates-lob
  • luke.birdeau
  • mg-lob
  • vmangwani
  • sachinlob
  • nick.perri
  • siddharthpant92
  • bethqiang
  • kplob
  • samkitsheth95
  • erin-doyle
  • rich_seviora_lob
  • jfdavidson
  • meussdorffer
  • shannamurry
  • davidnutting-lob
  • amaan_lob
  • team.platform.lob.com
  • elijah-lob
  • jlowsley-lob
  • barnabygo
  • james.cho
  • douglaje
  • lob-owner
  • graeme.lowe.lob