API Reference
Boom
HTTP-friendly error objects that carry status codes, messages, and metadata for consistent API error responses.
Official Documentation ↗CompatibilityThis documentation covers version
v10. Check the official docs for the latest API surface.Installation
npm
npm install @hapi/boompnpm
pnpm add @hapi/boomMethods
No methods match this filter.
Overview
Boom provides HTTP-friendly error objects that carry status codes, messages, and metadata for consistent API error responses. This reference lists the most frequently used APIs with accurate signatures and runnable snippets.
Core APIs
Boom.badRequest— Creates a 400 error instance with an optional message and attached data payload.Boom.notFound— Creates a 404 error suitable for missing resources.Boom.isBoom— Checks whether an error is a Boom error, optionally matching a specific status code.
Example
const Boom = require('@hapi/boom');
throw Boom.badRequest('Invalid payload', { field: 'email' });
Notes
Only the output.payload is safe to send to clients. Server errors hide internal details unless explicitly exposed.
Verification
Throw a badRequest and confirm the caught error exposes statusCode 400 and the same message in output.payload.
FAQ
- Where is the status code stored on a Boom error?
- At err.output.statusCode, with the client-safe body at err.output.payload; the raw message may be in err.message.
- How do I mark an error as non-sensitive for clients?
- Errors created 500 and above are not exposed by isServer unless you rethrow them with expose: true.
- Can Boom wrap a native error?
- Yes. Pass the original error as data or use Boom.boomify(err, { statusCode }) to attach HTTP semantics to it.
Report a problem with this API docOpens a pre-filled issue on GitHub.