Package Exports
- @bakjs/dev-errors
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@bakjs/dev-errors) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Development of this hapi plugin is supported by Future Studio University ๐
Join the Future Studio University and Skyrocket in Node.js
Introduction
A hapi plugin to return an error view for web requests, providing more details of the issue. Also, provides the error stacktrace within the browser and you can skip the extra look at your command line to catch the issue.

You can choose Youch to handle your error reporting by using the useYouch: true
option. hapi-dev-errors integrates
seamlessly with Youch and delegates the error handling, if activated. The view will look like this:

Requirements
This plugin uses async/await which requires Node.js v8 or newer.
Installation
Add @bakjs/dev-errors as a dependency to your project:
npm i -S @bakjs/dev-errors
# youโre using NPM shortcuts to (i)nstall and (-S)ave the module as a dependency
# NPM v5 users, this way is yours
npm i @bakjs/dev-errorsExamples
Check out the examples directory and get
an impression on how to configure hapi-dev-errors with the individual plugins options and how to customize the
error view.
Usage
hapi-dev-errors is disabled by default to avoid leaking sensitive error details during production.
Enable the plugin by define a "truthy" value for the showErrors option.
The most straight forward way to register the hapi-dev-errors plugin:
await server.register({
plugin: require('hapi-dev-errors'),
options: {
showErrors: process.env.NODE_ENV !== 'production'
}
})
// went smooth like chocolate :)Plugin Registration Options
The following plugin options allow you to customize the default behavior of hapi-dev-errors:
- showErrors:
(boolean), default:falseโ by default, the plugin is disabled and keeps hapi's default error handling behavior - useYouch:
(boolean), default:falseโ use Youch to handle and display the error instead of usinghapi-dev-errorโs default handling - template:
(string), no default โ provide the template name that you want to render withh.view(template, errorData)
await server.register({
plugin: require('hapi-dev-errors'),
options: {
showErrors: process.env.NODE_ENV !== 'production',
template: 'my-error-view'
}
})
// went smooth like chocolate :)Provided Values for Your Custom Error View
hapi-dev-errors supports the template option while registering the plugin. Provide a template name to
use your personal error template and not the default one shipped with hapi-dev-errors. In case you pass a string
value for the template name, the view will be rendered with h.view(template, errorData).code(500).
Available properties to use in your custom error view:
title: error title likeInternal Server ErrorstatusCode: HTTP response status code (always 500)message: error message, likeUncaught error: h.view(...).test is not a functionmethod: HTTP request method, likeGETurl: URL request path, like/signupheaders: HTTP request headers object, in key-value formatpayload: HTTP request payload, only available for HTTP methods other thanGET, in key-value formatstacktrace: error stacktrace
Feature Requests
Do you miss a feature? Please donโt hesitate to create an issue with a short description of your desired addition to this plugin.
Links & Resources
- hapi tutorial series with 80+ tutorials
- Youch - Pretty error reporting for Node.js
Contributing
- Create a fork
- Create your feature branch:
git checkout -b my-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request ๐
License
MIT ยฉ Future Studio
futurestud.io · GitHub @fs-opensource · Twitter @futurestud_io