Error Formatter for Hapi.js
Transforms Common Errors into a Hapi.js Reply object with the proper error code and payload.
Usage
- Reference this module in your
package.json
file'sdependencies
key:
"hapi-errors": "git@github.com:codemouse/hapi-errors.git"
- Use in a route handler:
const handleError = ;const repository = ; const routeHandler = req rep const reply = rep; return repository ;;
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, a500 Server Error
response will be created. -
reply
: the Hapi.js reply interface passed to your handler.