avocat
A utility to convert Objection database errors into Boom HTTP errors
Lead Maintainer: Daniel Cole
Installation
npm install @hapipal/avocat
Usage
See also the API Reference
Avocat is intended for use with hapi v19+, nodejs v12+, and Objection v2 (see v1 for lower support).
Avocat provides a single utility function Avocat.rethrow(error, [options])
which transforms database errors from Objection into Boom HTTP errors that are compatible with hapi.
'use strict';
const Hapi = require('@hapi/hapi');
const Avocat = require('@hapipal/avocat');
const User = require('./user-model');
const server = Hapi.server();
server.route({
method: 'get',
path: '/users/{id}',
handler(request) {
try {
return await User.query()
.findById(request.params.id)
.throwIfNotFound();
}
catch (err) {
Avocat.rethrow(err);
throw err;
}
}
});
The interface for Avocat is heavily inspired by Bounce.