A plugin for hapi.js to make responding with Boom errors a little less verbose by decorating the response toolkit with equivilent functions.
This module is tested against Node.js versions 8 and 10. The minimum required version of hapi.js is 17. If you require compatibility with an older version use version 3.0.1 or older.
npm install hapi-boom-decorators --save
const hapiBoomDecorators = require('hapi-boom-decorators');
const server = new Hapi.Server();
await server.register(hapiBoomDecorators);
The normal way of replying with a Boom error response:
const Boom = require('boom');
server.route({
method: 'GET',
path: '/resource/{id}',
handler: (request, h) => {
throw Boom.notFound();
}
});
With hapi-boom-decorators:
server.route({
method: 'GET',
path: '/resource/{id}',
handler: (request, h) => {
return h.notFound();
}
})
Check the Boom API documentation for all Boom error types. Every 4xx and 5xxx error, as well as boomify
can be called on the response toolkit.