The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

hapi.js - Friendly error pages with extension events

hapi.js - Friendly error pages with extension events

2:00
hapi automatically responds with JSON for any error passed to a route's `reply()` method. But what if your application needs errors rendered in HTML? This lesson shows how to implement friendly HTML error messages using hapi extension events.
Watch this lesson now
Avatar
egghead.io

hapi automatically responds with JSON for any error passed to a route's reply() method. But what if your application needs errors rendered in HTML? This lesson shows how to implement friendly HTML error messages using hapi extension events.

Avatar
Nish

How would we handle this for specific routes. For example, for failed login I would like to re-render the login page and show the error on there? Appreciate any pointers.

In reply to egghead.io
Avatar
Mike

You've got a few options. If you only need a customized behavior for one or two routes, I'd opt to just add logic to the onPreResponse event that checks for those routes and changes the behavior. As, your needs grow, you will likely want to move that logic into a hapi Plugin that will allow you to add the intended behavior to your route as configuration.

In reply to Nish
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?