Skip to content

Instantly share code, notes, and snippets.

@evilpacket
Created May 17, 2014 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evilpacket/104f0ffa7fcff6ea6b94 to your computer and use it in GitHub Desktop.
Save evilpacket/104f0ffa7fcff6ea6b94 to your computer and use it in GitHub Desktop.
hapi.js add something to context every request
// Deal with errors
server.ext('onPreResponse', function(request, reply) {
var response = request.response;
// Decorate with session
if (!response.isBoom) {
if (request.response.source && request.response.source.context) {
request.response.source.context.session = {user: request.auth.credentials};
}
return reply();
}
// Replace error with friendly HTML
var error = response;
var ctx = {
message: error
};
reply.view('error', ctx);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment