Git Product home page Git Product logo

hapi-error-page's Introduction

hapi-error-page Build status for hapi Error Page

Friendly error pages for humans

This hapi plugin makes it easy to return beautiful HTML error pages to your users.

Why?

  • Errors in hapi are displayed as JSON by default.
  • JSON is good for machines but bad for people.
  • Works with AJAX / APIs (respects the Accept header).

Install

npm install hapi-error-page --save

Usage

Register the plugin on your server to enable friendly error pages.

const hapi = require('hapi');
const vision = require('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 from a view file named error.html. You can, of course, use other templating engines instead (see the vision documentation for details).

Please use 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 for more details.

  1. Fork it.
  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.

License

MPL-2.0 © Seth Holladay

Go make something, dang it.

hapi-error-page's People

Contributors

sholladay avatar venikman avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.