Created
May 17, 2014 02:20
-
-
Save evilpacket/104f0ffa7fcff6ea6b94 to your computer and use it in GitHub Desktop.
hapi.js add something to context every request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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