Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@hapipal/avocat

Package Overview
Dependencies
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hapipal/avocat

A utility to convert Objection database errors into Boom HTTP errors

  • 3.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
515
increased by15.99%
Maintainers
3
Weekly downloads
 
Created
Source

avocat

A utility to convert Objection database errors into Boom HTTP errors

Build Status Coverage Status

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 or v3 (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'); // An Objection model bound to a knex instance

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); // Throws a 404 Not Found if user does not exist
            throw err;
        }
    }
});

Extras

The interface for Avocat is heavily inspired by Bounce.

Keywords

FAQs

Package last updated on 12 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc