Skip to content

Using promises in prehandlers causes exceptions to be swallowed in handlers.  #3242

@johnbrett

Description

@johnbrett

I have the following test case, when you send a request to the server it will hang. It doesn't respond, and nothing is logged to the console (this cost me hours of debugging earlier :/)

const Hapi = require('hapi');

const server = new Hapi.Server();
server.connection({ host: 'localhost', port: 8999 });

const pre = (request, reply) => {
  return reply(Promise.resolve('FROM PRE HANDLER'))
};

server.route({
    method: 'GET',
    path:'/', 
    config: {
      pre: [{ method: pre, assign: 'test' }]
    },
    handler: function (request, reply) {

        throw new Error('this is an error ' + request.pre.test)
        return reply('hello world ' + request.pre.test);
    }
});

server.start((err) => {
    if (err) { throw err; }
    console.log('Server running at:', server.info.uri);
});

@nlf, I saw this which might be related #3102 but the fix 8babca3 doesn't cover this either. I'm trying to debug this further and provide a fix, but I'm not a promises expert, finding it tough to get to the bottom of it so maybe someone might be able to help!

This is with hapi@13.5.0 on Node 6.

Metadata

Metadata

Assignees

Labels

bugBug or defect

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions