diff --git a/packages/error-reporting/src/interfaces/hapi.js b/packages/error-reporting/src/interfaces/hapi.js index 9f8855a2853..35ee6eeaca7 100644 --- a/packages/error-reporting/src/interfaces/hapi.js +++ b/packages/error-reporting/src/interfaces/hapi.js @@ -92,7 +92,7 @@ function makeHapiPlugin(client, config) { client.sendError(em); } - if (isObject(reply) && isFunction(reply.continue)) { + if (reply && isFunction(reply.continue)) { reply.continue(); } }); diff --git a/packages/error-reporting/test/unit/interfaces/hapi.js b/packages/error-reporting/test/unit/interfaces/hapi.js index 0ed136db10b..ae2c491d215 100644 --- a/packages/error-reporting/test/unit/interfaces/hapi.js +++ b/packages/error-reporting/test/unit/interfaces/hapi.js @@ -113,16 +113,32 @@ describe('Hapi interface', function() { afterEach(function() { fakeServer.removeAllListeners(); }); - it('Should call continue when a boom is emitted', function(done) { - plugin.register(fakeServer, null, function() {}); - fakeServer.emit(EVENT, {response: {isBoom: true}}, - { - continue: function() { - // The continue function should be called - done(); + it('Should call continue when a boom is emitted if reply is an object', + function(done) { + plugin.register(fakeServer, null, function() {}); + fakeServer.emit(EVENT, {response: {isBoom: true}}, + { + continue: function() { + // The continue function should be called + done(); + } } - } - ); + ); + }); + it('Should call continue when a boom is emitted if reply is a function', + function(done) { + // Manually testing has shown that in actual usage the `reply` object + // provided to listeners of the `onPreResponse` event can be a function + // that has a `continue` property that is a function. + // If `reply.continue()` is not invoked in this situation, the Hapi + // app will become unresponsive. + plugin.register(fakeServer, null, function() {}); + var reply = function() {}; + reply.continue = function() { + // The continue function should be called + done(); + }; + fakeServer.emit(EVENT, {response: {isBoom: true}}, reply); }); it('Should call sendError when a boom is received', function(done) { var fakeClient = {