https://github.com/sholladay/hapi-error-page
Friendly error pages for humans
https://github.com/sholladay/hapi-error-page
error hapi plugin template views
Last synced: about 1 month ago
JSON representation
Friendly error pages for humans
- Host: GitHub
- URL: https://github.com/sholladay/hapi-error-page
- Owner: sholladay
- License: mpl-2.0
- Created: 2017-02-20T16:53:12.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-02-26T19:38:23.000Z (over 5 years ago)
- Last Synced: 2025-04-27T04:02:55.178Z (about 1 month ago)
- Topics: error, hapi, plugin, template, views
- Language: JavaScript
- Homepage:
- Size: 85 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# hapi-error-page [](https://travis-ci.com/sholladay/hapi-error-page "Builds")
> Friendly error pages for humans
This [hapi](https://hapijs.com) plugin makes it easy to return beautiful HTML error pages to your users.
## Why?
- Errors in hapi are displayed as [JSON](https://json.org) by default.
- JSON is good for machines but bad for people.
- Works with AJAX / APIs (respects the [`Accept`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept) header).## Install
```sh
npm install hapi-error-page
```## Usage
Register the plugin on your server to enable friendly error pages.
```js
const hapi = require('@hapi/hapi');
const vision = require('@hapi/vision');
const errorPage = require('hapi-error-page');const server = hapi.server();
const init = async () => {
await server.register([vision, errorPage]);
server.views({
engines : { html : handlebars },
relativeTo : __dirname,
path : '.'
});
server.route({
method : 'GET',
path : '/',
handler() {
throw new Error('uh oh');
}
});
await server.start();
console.log('Server ready:', server.info.uri);
};init();
```Visiting the above route will return an HTML error page rendered by [Handlebars](https://github.com/wycats/handlebars.js/) from a view file named `error.html`. You can, of course, use other templating engines instead (see the [vision](https://github.com/hapijs/vision) documentation for details).
Please use [boom](https://github.com/hapijs/boom) to construct errors instead of `new Error()`, so that we can deliver more useful messages. This project will function correctly either way, but `boom` is preferred.
## Contributing
See our [contributing guidelines](https://github.com/sholladay/hapi-error-page/blob/master/CONTRIBUTING.md "Guidelines for participating in this project") for more details.
1. [Fork it](https://github.com/sholladay/hapi-error-page/fork).
2. Make a feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. [Submit a pull request](https://github.com/sholladay/hapi-error-page/compare "Submit code to this project for review").## License
[MPL-2.0](https://github.com/sholladay/hapi-error-page/blob/master/LICENSE "License for hapi-error-page") © [Seth Holladay](https://seth-holladay.com "Author of hapi-error-page")
Go make something, dang it.