drboom
v1.1.0
Published
Detect and convert errors into Hapi Boom HTTP errors.
Downloads
5
Readme
Dr. Boom
Dr. Boom detects errors being passed into Hapi's HTTP replies and converts them into the appropriate HTTP Error.
This allows you to pass the resulting error and result from a database query to reply without having to do special error handling.
Example
For example, to detect Joi validation errors:
let Hapi = require('hapi');
server.register([
{
register: require('drboom'),
options: {
plugins: [require('drboom-joi')({})]
}
}
], (err) => {
// ...
});
Then when a route serves an a Joi validation result as the first argument, the reply is automatically converted to an HTTP 400 Bad Request error.
Writing a Dr. Boom Plugin
A Dr. Boom plugin is an object with two functions, detect
and handle
.
detect(value, request, reply)
value
is the first argument sent to reply.
return: Boolean, false meaning that you didn't detect an error your handler can deal with.
handle(value, request, reply)
value
is the first argument sent to reply.
return: Boom error or falsey.