1.0.6 • Published 9 years ago

hapi-errors v1.0.6

Weekly downloads
35
License
-
Repository
github
Last release
9 years ago

Error Formatter for Hapi.js

Transforms Common Errors into a Hapi.js Reply object with the proper error code and payload.

Usage

  1. Reference this module in your package.json file's dependencies key:

    "hapi-errors": "git@github.com:codemouse/hapi-errors.git"
  2. Use in a route handler:

    const handleError = require('hapi-errors');
    const repository = require('./repository');
    
    const routeHandler = (req, rep) {
      const reply = rep;
      return repository.get(req.params.id)
      .then((item) => {
        return reply(item);
      })
      .catch((err) => {
        return handleError(err, reply);
      });
    };

API

The hapi-errors module is just a single function that takes two parameters:

  • err: a caught error. If the error is a part of the Common Errors package, an appropriate Hapi.js Response object will be created. Otherwise, a 500 Server Error response will be created.

  • reply: the Hapi.js reply interface passed to your handler.

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago